Start with the question:
XOR Pairs
Time limit:2000/1000 ms (Java/Others)
Memory limit:128000/64000 KB (Java/others) submitstatusproblem description
Long long ans = 0;
For (INT I = 1; I <= N; I ++)
For (Int J = I + 1; j <= N; j ++)
For (int K = J + 1; k <= N; k ++)
If (I ^ J ^ K) = 0) ans ++;
There are about 10000 groups of input data. Each group of data has one n (1 <= n <= 10 ^ 9). For each group of data, output one row, anssample Input
101112
Sample output
101317
At first glance, there is only one number in the input, and then there is an output, which is likely to be a regular expression.
After the table is typed, it seems that the rule is not very obvious. Subtract two adjacent items and then find the rule, ''''''
Then there is the constructor. The idea is to first find the power Number of the next Power Sum closest to the input n, then, find the sum of the arithmetic difference series ending with the power-1 of 2, and then find the number that can be obtained by adding the extra arithmetic difference series. A small adjustment may be required in the middle.
Code:
1 /* 2 * this code is made by sineatos 3 * Problem: 1183 4 * Verdict: Accepted 5 * Submission Date: 2014-07-31 14:59:31 6 * Time: 8MS 7 * Memory: 1088KB 8 */ 9 #include <cstdio>10 #include <cstring>11 #include <algorithm>12 #define MAX 10000213 #define ll long long14 using namespace std;15 16 int main()17 {18 ll n,i,c,r;19 while(~scanf("%lld",&n))20 {21 if(n<2) printf("0\n");22 else if(n==3) printf("1\n");23 else24 {25 ll sum=0;26 c=0;27 for(i=1; (c+i)<n; i<<=1)28 {29 c+=i;30 sum+=i*(i-1)/2;31 }32 r=n-c;33 sum+=(1+(r-1))*(r-1)/2;34 printf("%lld\n",sum);35 }36 }37 38 return 0;39 }/* XOR pairs */