洛谷 P3908 数列之异或

题目传送门

很显然的结论,可以打表找规律.

#include<iostream>
#include<cstdio>
#include<cstring>

using namespace std;

long long n,m,k;

inline long long mx() {
	long long s = 0,w = 1;
	char ch = getchar();
	while(ch < '0' || ch > '9') {
		if(ch == '-') w = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		s = s * 10 + (ch - '0');
		ch = getchar();
	}
	return s * w;
}

int main() {
	n = mx();
	if(n == 1) {
		printf("1");
		return 0;
	}
	n--;
	if(n % 4 == 0) {
		printf("1");
		return 0;
	}
	if(n % 4 == 2) {
		printf("0");
		return 0;
	}
	if(n % 4 == 1) {
		printf("%lld",(n + 1) ^ 1);
		return 0;
	}
	if(n % 4 == 3) {
		printf("%lld",(n + 1) ^ 0);
		return 0;
	}
	return 0;
} 
posted @ 2020-11-22 21:51  Mr^Simon  阅读(97)  评论(0编辑  收藏  举报