# UVa 12716 (GCD = = XOR) GCD XOR

Source: Internet
Author: User

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

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.