UVA 12716 GCD XOR(数论+枚举+打表)
题意:给你一个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 - B = gcd(A, B)
设 C = gcd(A, B),那么我们能够枚举C和A。通过A-C求出B,再验证A xor B 是否等于C就可以
这里的枚举是仿照筛素数的方法,对于每个A。我们求出一共同拥有多少C满足条件,记为ans[A],那么最后仅仅须要累加一下就能够。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<ctime>
#define eps 1e-6
#define LL long long
#define pii (pair<int, int>)
//#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std; const int maxn = 30000000 + 10000;
//const int INF = 0x3f3f3f3f;
int n;
int ans[maxn]; void init() {
for(int c = 1; c <= 30000000; c++) {
for(int a = c<<1; a <= 30000000; a += c) {
int b = a - c;
if((a^b) == a-b) ans[a]++;
}
}
for(int i = 1; i <= 30000000; i++) ans[i] += ans[i-1];
} int main() {
//freopen("input.txt", "r", stdin);
int T; cin >> T;
int kase = 0;
init();
while(T--) {
scanf("%d", &n);
printf("Case %d: %d\n", ++kase, ans[n]);
}
return 0;
}
UVA 12716 GCD XOR(数论+枚举+打表)的更多相关文章
- UVA.12716 GCD XOR (暴力枚举 数论GCD)
UVA.12716 GCD XOR (暴力枚举 数论GCD) 题意分析 题意比较简单,求[1,n]范围内的整数队a,b(a<=b)的个数,使得 gcd(a,b) = a XOR b. 前置技能 ...
- UVA - 12716 GCD XOR(GCD等于XOR)(数论)
题意:输入整数n(1<=n<=30000000),有多少对整数(a, b)满足:1<=b<=a<=n,且gcd(a,b)=a XOR b. 分析:因为c是a的约数,所以枚 ...
- UVa 12716 - GCD XOR(筛法 + 找规律)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA 12716 GCD XOR (异或)
题意:求出[1,n]中满足gcd(a,b)=a xor b,且1<=a<=b<=n的对数 题解:首先a xor b = c,则a xor c = b,而b是a的约数,则可以使用素数筛 ...
- UVa 12716 (GCD == XOR) GCD XOR
题意: 问整数n以内,有多少对整数a.b满足(1≤b≤a)且gcd(a, b) = xor(a, b) 分析: gcd和xor看起来风马牛不相及的运算,居然有一个比较"神奇"的结论 ...
- UVA 12716 GCD XOR
https://vjudge.net/problem/UVA-12716 求有多少对整数(a,b)满足:1<=b<=a<=n,且gcd(a,b)=a XOR b 结论:若gcd(a, ...
- UVA 12716 GCD XOR【异或】
参考:http://www.cnblogs.com/naturepengchen/articles/3952145.html #include<stdio.h> #include<s ...
- UVa 12716 GCD XOR (简单证明)
题意: 问 gcd(i,j) = i ^ j 的对数(j <=i <= N ) N的范围为30000000,有10000组例子 思路:GCD(a,b) = a^b = c GCD(a/c ...
- UVa 12716 && UVaLive 6657 GCD XOR (数论)
题意:给定一个 n ,让你求有多少对整数 (a, b) 1 <= b <= a 且 gcd(a, b) = a ^ b. 析:设 c = a ^ b 那么 c 就是 a 的约数,那么根据异 ...
随机推荐
- jquery复制到剪贴板
<!DOCTYPE html> <html> <head> <title>ZeroClipboard Test</title> <me ...
- ERROR in xxxx.js from UglifyJS——配置版本混杂版
常规解决套路可以参考这篇:https://segmentfault.com/a/11... 我采用了上面的做法,依然没法解决.我采用的是vue-cli脚手架自动生成的项目结构: vue-cli版本 2 ...
- caioj 1158 欧拉函数
直接套模板,这道题貌似单独求还快一些 解法一 #include<cstdio> #include<cctype> #define REP(i, a, b) for(int i ...
- [MST] Attach Behavior to mobx-state-tree Models Using Actions
Models are not just a nifty feature for type checking. They enable you to attach behavior to your ac ...
- 生成apk文件遇到的编译问题error: format not a string literal and no format arguments
编译错误时使用的android-ndk为r9的版本号.报下面错误: "Compile++ thumb : cocosdenshion_static <= SimpleAudioEngi ...
- Connect to MongoDB
https://docs.mongodb.com/getting-started/csharp/client/ MongoDB C# Driver is the officially supporte ...
- BZOJ 3083 树链剖分+倍增+线段树
思路: 先随便选个点 链剖+线段树 1操作 就直接改root变量的值 2操作 线段树上改 3操作 分成三种情况 1.new root = xx 整个子树的min就是ans 2. lca(new roo ...
- PowerDesigner怎么调出工具箱?
PowerDesigner怎么调出工具箱? 如图操作:
- CUDA笔记12
这几天配置了新环境,而且流量不够了就没写. 看到CSDN一个人写了些机器学习的笔记,于是引用一下http://blog.csdn.net/yc461515457/article/details/504 ...
- jquery on event
<!doctype html> <html lang="en"> <head> <meta charset="utf-8&quo ...