原题链接
遇到这种数学题,像我这种数学很烂的当然是上来就打表啦。
//以下是前30个数的表。
1 -> 1
2 -> 3
3 -> 0
4 -> 4
5 -> 1
6 -> 7
7 -> 0
8 -> 8
9 -> 1
10 -> 11
11 -> 0
12 -> 12
13 -> 1
14 -> 15
15 -> 0
16 -> 16
17 -> 1
18 -> 19
19 -> 0
20 -> 20
21 -> 1
22 -> 23
23 -> 0
24 -> 24
25 -> 1
26 -> 27
27 -> 0
28 -> 28
29 -> 1
30 -> 31
很容易看出来有四种情况。
- \(n \% 4 = 0\),则答案为\(n\)。
- \(n \% 4 = 1\),则答案为\(1\)。
- \(n \% 4 = 2\),则答案为\(n + 1\)。
- \(n \% 4 = 3\),则答案为\(0\)。
我数学差,别问我为什么
于是很愉快的\(A\)了。
#include<cstdio>
using namespace std;
int main()
{
long long n, x;
scanf("%lld", &n);
x = n % 4;
printf("%lld", x ^ 3 ? !x ? n : x ^ 1 ? n + 1 : 1 : 0);
return 0;
}