【洛谷】P3908 异或之和(异或)

题目描述

1 \bigoplus 2 \bigoplus\cdots\bigoplus N12N 的值。

A \bigoplus BAB 即AA , BB 按位异或。

输入输出格式

输入格式:

 

1 个整数NN。

 

输出格式:

 

1 个整数,表示所求的值。

 

输入输出样例

输入样例#1:
3
输出样例#1:
0

说明

• 对于50% 的数据,1 \le N \le 10^61N106;

• 对于100% 的数据,1 \le N \le 10^{18}1N1018。

------------------------------------------------------------------------

分析:又是数学题。。。。我承认我想了30min没想出来后,看了题解。

  其实呢是通过公式O(1)时间判断的,公式详见代码。

  吐槽:为什么博客园不支持这里的数学公式,难道只是这道异或之和?

 1 #include <cstdio>
 2 #include <algorithm>
 3 using namespace std;
 4 typedef unsigned long long ull;
 5 ull calc(ull n)
 6 {
 7     if(n%4==0) return n;
 8     if(n%4==1) return 1;
 9     if(n%4==2) return n+1;
10     if(n%4==3) return 0;
11 }
12 int main()
13 {
14     unsigned long long n;
15     scanf("%lld",&n);
16     printf("%lld",calc(n));
17     return 0;
18 }
posted @ 2017-10-19 22:09  noble_(noblex)  阅读(301)  评论(0编辑  收藏  举报
/* */