[Idea] A ^ B = C is equivalent to a ^ c = B, so enumeration of A and C is true, while enumeration of A and C is positive. Therefore, the efficient algorithm is as follows: the relationship between C and A is used to reduce the cycle. C must be placed out of the loop because C is rarely used. In fact, this question is required: c = A-B (regular), c = a ^ B
The following is the AC code of Goshen, which is very powerful:
# Include <cstdio> # include <iostream> # include <cmath> # include <string> using namespace STD; # define maxn 30000000int s [30000000 + 10]; int Init () {int sum = 0; For (INT c = 1; C <= maxn/2; C ++) {// For (int A = C + C; A <= maxn; A + = c) {int B = a-c; If (a ^ B) = C) s [a] ++; // all possibilities of. Because when a <n calculates N, it must add up all the first n items} For (INT I = 2; I <= maxn; I ++) // The total number of I, really clever s [I] + = s [I-1];} int main () {int counts = 0, num; scanf ("% d", & num); Init (); While (Num --) {int N; scanf ("% d", & N ); printf ("case % d: % d \ n", ++ counts, s [N]);} return 0 ;}