UVa 12716 GCD XOR (简单证明)
2017-06-14 14:41
281 查看
题意: 问 gcd(i,j) = i ^ j 的对数(j <=i <= N ) N的范围为30000000,有10000组例子
思路:GCD(a,b) = a^b = c
GCD(a/c,b/c) = 1 (1)
(a-b) <= c (2)
(a/c-b/c) <=1 (3)
(1)(3) => a/c-b/c = 1=> a-b=c
#include <iostream> #include <cstdio> #include <cstring> #include <vector> #include <string> #include <algorithm> #include <queue> #include <set> #include <map> #include <cmath> using namespace std; const int maxn = 30000000+10; typedef long long LL; int N; int ret[maxn]; void init() { for(int i = 3; i < maxn; i+=2) ret[i] = 1; for(int i = 2; i < maxn/2; i++) { for(int j = i+i; j < maxn; j += i) { int k = j-i; if( (k^j) == i){ ret[j]++; } } } for(int i = 1; i < maxn; i++) ret[i] += ret[i-1]; } int main(){ int ncase,T=1; init(); cin >> ncase; while(ncase--) { scanf("%d",&N); printf("Case %d: %d\n",T++,ret ); } return 0; }
相关文章推荐
- UVa 12716 GCD XOR (简单证明)
- uva 12716 - GCD XOR
- UVA-12716 - GCD XOR
- GCD XOR UVA - 12716 (gcd(),异或)
- UVA 12716(p318)----GCD XOR
- UVa--12716 GCD XOR(math)
- 数论,优化,预处理(GCD 等于 XOR,uva 12716)
- uva12716 GCD等于XOR 筛法枚举
- UVA 12716 GCD XOR(数论+枚举+打表)
- uva12716 GCD XOR(打表找规律+筛法)
- Uva 12716-GCD XOR(数论,枚举,xor)
- UVa 12716 && UVaLive 6657 GCD XOR (数论)
- UVA 12716 GCD XOR (数论,规律)
- UVa 12716 (GCD == XOR) GCD XOR
- Uva12716:GCD XOR
- uva12716GCD等于XOR(预处理)
- 【UVA】12716-GCD XOR
- UVA 12716 GCD XOR
- 【数论】GCD XOR, ACM/ICPC Dhaka 2013, UVa12716 【异或】【好题】
- UVA 12716 GCD XOR