Test instructions
Q How many pairs of integers a, B are satisfied (1≤b≤a) and gcd (A, B) = XOR (A, B) within the integer n
Analysis:
GCD and Xor seem irrelevant to the operation, there is actually a more "magical" conclusion:
Set GCD (A, B) = XOR (A, b) = c, C = A-a
here
There is a more rigorous proof.
With this conclusion, we can enumerate the approximate C, then enumerate the multiples a of C, and then, based on C = A-B, verify that B satisfies gcd (A, B) = XOR (A, B)
1#include <cstdio>2 Const intMAXN =30000000;3 intANS[MAXN +Ten];4 5 intMain ()6 {7 //freopen ("12716in.txt", "R", stdin);8 9 for(intc =1; C <= MAXN; C++)Ten { One for(intA =2*c; a <= maxn; A + =c) A { - intb = A-C; - if((a ^ c) = = b) ans[a]++; the } - } - for(inti =1; I <= MAXN; ++i) ans[i] + = ans[i-1]; - + intT, N; -scanf"%d", &T); + for(intKase =1; Kase <= T; ++Kase) A { atscanf"%d", &n); -printf"Case %d:%d\n", Kase, Ans[n]); - } - - return 0; -}
code June
UVa 12716 (GCD = = XOR) GCD XOR