uva12716 GCD XOR】的更多相关文章

个人博客:http://acbingo.cn/2015/06/04/uva12716/ 被紫薯上*和素数筛法类似*这句话给误解了= =,一直以为存在某种关系,在枚举c或者a时,可以根据当前的答案,筛掉一些后面的值...结果想了好长时间也没想明白. 还是枚举c比较简单,因为c是a的约数,然后根据c生成a. #define maxn 30000000 ; }; int a,b,c,n; int init(){ ;c<=maxn/;c++) for (a = c + c ; a <= maxn ;…
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u010682557/article/details/36204645 题目给你一个N,让你求 两个数字 A,B,且   A>=B<=N,是的 gcd(A,B) == A^B N的范围是 3*10^7大的吓人一開始没敢想构造.由于就算构造开的数组也太大了,已经10^7了.后来想了半天在^运算这里也没有想出来什么,所以没办法还是大胆构造吧,构造就去依照他题目的意思来了,构造两个数字 i,j当中j是i…
/** 题目: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…
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…
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的因子,所以在枚举的…
规律题,打表找规律即可发现 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…
不同的枚举方法,效率完全不同.值得记录一下! #include <cstdio> #include <cstring> , count = ; ]; void pre() { count = ; memset(cnt, , sizeof(cnt)); ; a <= ; a++) { ; c < a; c++) { && ((a-c)^a)==c) { count++; } } cnt[a-] = count; } } int main(void) { f…
https://vjudge.net/problem/UVA-12716 求有多少对整数(a,b)满足:1<=b<=a<=n,且gcd(a,b)=a XOR b 结论:若gcd(a,b)= a XOR b = c,则c=a-b 证明: 1.任意两个数a,b,若a>=b,则 a-b <= a XOR b 2.若 c为a.b的最大公约数,且a>=b,则 a-b >= c 假设存在 c 使得 a-b > c,则 c<a-b<=a XOR b,即 c&l…
题意:给出N,1<=b<=a<=N,求满足gcd(a,b)=a xor b的pair (a,b)的个数 有个重要的结论:若gcd(a,b)=a xor b=c,那么b=a-c 如果一个个求gcd肯定不行. 令f[i]表示满足条件的pair (a,b)中,a=i的个数 枚举c,令a是c的所有倍数,求出b=a-c.若b=a xor c那么f[a]++ 最后求f[]的前缀和S[],那么答案就是S[N](要求a<=N啦~) #include <stdio.h> #include…