UVA.12716 GCD XOR (暴力枚举 数论GCD)】的更多相关文章

UVA.12716 GCD XOR (暴力枚举 数论GCD) 题意分析 题意比较简单,求[1,n]范围内的整数队a,b(a<=b)的个数,使得 gcd(a,b) = a XOR b. 前置技能 XOR的性质 GCD 由于题目只给出一个n,我们要求对数,能做的也始终暴力枚举a,b,这样就有n^2的复杂度,由于n很大,根本过不了. 于是我们就想用到其中一些性质,如XOR 与GCD,不妨假设 a xor b = c,并且根据题意还知道, gcd(a,b) = c,也就说明c一定是a的因子,所以在枚举的…
  Problem G. Birthday Cake Background Lucy and Lily are twins. Today is their birthday. Mother buys a birthday cake for them.Now we put the cake onto a Descartes coordinate. Its center is at (0,0), and the cake's length of radius is 100. There are 2N…
[题意]:输入正整数n,用0~9这10个数字不重复组成两个五位数abcde和fghij,使得abcde/fghij的商为n,按顺序输出所有结果.如果没有找到则输出“There are no solutions for N.”.这里2<=n<=79. [分析]: 1.因为n>=2,且abcde=fghij×n,满足abcde>fghij.若a=0,则fghij的最小值为12345,abcde<fghij,矛盾.所以a≠0. 2.因为a≠0,所以12345<=abcde&l…
10603 Fill There are three jugs with a volume of a, b and c liters. (a, b, and c are positive integers not greater than 200). The rst and the second jug are initially empty, while the third is completely lled with water. It is allowed to pour water f…
 题意:给你一个N,让你求有多少组A,B,  满足1<= B <= A <= N, 且 gcd(A,B) = A XOR B. 思路:首先我们能够得出两个结论: A-B >= A%B >= gcd(A, B) A xor B >= A-B 所以说A xor B >= A-B >= gcd(A, B),然后就能够推出 A xor B = A - B = gcd(A, B) =>    A xor B = A - B  &&  A -…
/** 题目:GCD XOR UVA 12716 链接:https://vjudge.net/problem/UVA-12716 题意:给定一个n,找多少对(a,b)满足1<=b<=a<=n,gcd(a,b)=a^b: 思路: 打表找规律发现:满足条件的结果一定满足,gcd(a,b) = a-b; 即:先确定每一个a以及它的约数c可以获得,b = a-c; 如果a^b=c 那么满足. 时间复杂度nlg(n) */ #include <iostream> #include &l…
GCD XORGiven an integer N, nd how many pairs (A; B) are there such that: gcd(A; B) = A xor B where1 B A N.Here gcd(A; B) means the greatest common divisor of the numbers A and B. And A xor B is thevalue of the bitwise xor operation on the binary repr…
题目链接 Solution 此题,用到的结论都是比较浅显的,但是,我竟然没想到反过来枚举... 只有50分... 被自己蠢哭... 结论比较浅显: 1.对于两个正整数\(a\),\(b\),设 \(gcd(a,b)=k\),则存在\(gcd(a/k,b/k)=1\). 也就是说 \(x=k_1*a_1\),\(a_0=k_2*a_1\),它们最大公约数为\(a_1\),那么要求 \(k_1\) 与 \(k_2\) 必须互质,否则它们的最大公约数会是 \(gcd(k_1,k_2)*a_1\). 2…
规律题,打表找规律即可发现 a xor b >= a - b >= gcd(a, b), 如果 a xor b = gcd(a, b) = c 则 c = a - b 枚举倍数c和a判断b即可 但是我主要想讲的是这道题要注意的,就是在跑循环时,一定要注意数组是否越界,比如 int a[maxn]; scanf("%d",&T); for(int i=1;i<=maxn;++i){ a[i]=i; } 这样写会造成你读入的T被覆盖,导致输出超限,因为数组a[ma…
GCD XORGiven an integer N, nd how many pairs (A; B) are there such that: gcd(A; B) = A xor B where1 B A N.Here gcd(A; B) means the greatest common divisor of the numbers A and B. And A xor B is thevalue of the bitwise xor operation on the binary repr…