博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
GCD XOR uvalive6657
阅读量:6980 次
发布时间:2019-06-27

本文共 1486 字,大约阅读时间需要 4 分钟。

GCD XOR

Given an integer N, nd 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 rst 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 rst 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.
Explanation
Sample 1: For N = 7, there are four valid pairs: (3, 2), (5, 4), (6, 4) and (7, 6).
Sample Input
2
7
20000000
Sample Output
Case 1: 4
Case 2: 34866117

 

1 #include 
2 #include
3 #include
4 #include
5 #include
6 using namespace std; 7 int ans[30000010]={
0}; 8 void init() 9 {10 int i,j;11 for(i=1;i<30000010;i++)12 {13 for(j=i+i;j<30000010;j+=i)14 if((j^(j-i))==i)ans[j]++;15 }16 for(i=1;i<30000010;i++)ans[i]+=ans[i-1];17 }18 int main()19 {20 int t,i,n;21 init();22 scanf("%d",&t);23 for(i=1;i<=t;i++)24 {25 scanf("%d",&n);26 printf("Case %d: %d\n",i,ans[n]);27 }28 }
View Code

 

转载于:https://www.cnblogs.com/ERKE/p/3677456.html

你可能感兴趣的文章
Jmeter干货 不常用却极其有用的几个地方
查看>>
浅谈同一家公司多个系统,共用登录用户名和密码
查看>>
京东二面的几个问题
查看>>
PHP和MySQL Web开发从新手到高手,第8天-创建categories管理页面
查看>>
1-2 postman工具简介
查看>>
如何提升 CSS 选择器的性能?
查看>>
Mac原生Terminal快速登录ssh
查看>>
wamp多站点访问设置
查看>>
Android深入浅出系列之Android工具的使用—模拟器(一)
查看>>
矩形的个数
查看>>
jenkins自动化部署工具
查看>>
Same binary weight (位运算)
查看>>
Unique Binary Search Trees java实现
查看>>
笔试算法题(58):二分查找树性能分析(Binary Search Tree Performance Analysis)
查看>>
Django内置Admin
查看>>
一个疯狂想法
查看>>
ARM体系结构
查看>>
用户输入一个数字,找到所有能够除尽它的数的总个数
查看>>
PhpMyAdmin的简单安装和一个mysql到Redis迁移的简单例子
查看>>
构建之法读后感part6
查看>>