Uva12716:GCD XOR
来源:互联网 发布:淘宝天猫内购券 编辑:程序博客网 时间:2024/06/01 07:38
Given an integer N, find how many pairs (A, B) are there such that: gcd(A, B) = A xor B where
1 ≤ B ≤ A ≤ N.
Here gcd(A, B) means the greatest common divisor of the numbers A and B. And A xor B is the
value of the bitwise xor operation on the binary representation of A and B.
Input
The first line of the input contains an integer T (T ≤ 10000) denoting the number of test cases. The
following T lines contain an integer N (1 ≤ N ≤ 30000000).
Output
For each test case, print the case number first in the format, ‘Case X:’ (here, X is the serial of the
input) followed by a space and then the answer for that case. There is no new-line between cases.
Sample Input
2720000000
Sample Output
Case 1: 4Case 2: 34866117
Explanation
Sample 1: For N = 7, there are four valid pairs: (3, 2), (5, 4), (6, 4) and (7, 6).
【题目描述】
给你一个正整数n,问你区间[1, n]中有多少无序数对(a, b)满足
【简要题解】
假设
第一个不等式是显然的。
而由于
所以
所以就有
我们可以枚举
时间复杂度:
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;int solve(int n){ int ans = 0, e = n >> 1; for(int c = 1; c <= e; ++c) for(int a = c << 1; a <= n; a += c) if((a^c) == a-c) ans++; return ans;}int main(){ int n; cin >> n; cout << solve(n) << endl; return 0;}
- Uva12716:GCD XOR
- UVA12716 GCD XOR
- UVa12716 GCD XOR
- UVa12716 GCD XOR
- uva12716 GCD XOR
- UVA12716 GCD XOR
- 数论--uva12716 GCD XOR
- UVA12716 GCD XOR 数论数学构造
- UVA12716 GCD XOR 数论数学构造
- 例题10-5 GCD等于XOR UVa12716
- UVa12716 - GCD XOR(数论数学构造)
- uva12716 GCD XOR(打表找规律+筛法)
- uva12716 GCD等于XOR 筛法枚举
- 例题10-5 GCD等于XOR UVa12716
- 数学方法(GCD XOR Uva12716)
- UVA12716 GCD等于XOR 数论 枚举
- 【数论】GCD XOR, ACM/ICPC Dhaka 2013, UVa12716 【异或】【好题】
- UVa12716
- Android Gallery 3D效果
- 黑马程序员--面向对象设计
- 继承
- 九度OJ 题目1491:求1和2的个数
- Jetty9 实战
- Uva12716:GCD XOR
- 确定字符互异
- eclipse 快捷键
- 1515 - Pool construction(最大流最小割模型)
- Android多线程断点下载
- 渗透中寻找突破口的那些事
- Manaher算法总结
- mysql字符集的一些。
- 接口