SOJ-4309 Sum of xor

来源:互联网 发布:警用手铐淘宝有的买吗 编辑:程序博客网 时间:2024/04/29 20:17

由n^(n+1)=1,n为偶数即可分类求得。

1^1=0,0^1=1,0^0=0,异或满足交换律。

#include<iostream>#include<cstdio>#include<cstring>typedef long long LL;using namespace std ;LL get_ans(LL n){    if(n&1) return (n-1)%4==0?1:0;    return (n-2)%4==0? n^1:n;}int main(){LL n;    while(scanf("%lld",&n)!=EOF){printf("%lld\n",get_ans(n));    } return 0 ;}