uval 6657 GCD XOR
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
题意:给出n,求出a<=n,b<=n,且gcd(a,b)==a xor b 的对数
思路:找规律得出的解,数学证明暂无,以后如果想出再补(八成补不出来= =)。找规律得出,如果a,b(a<b)满足上述条件,那么a'=a/gcd(a,b),b'=b/gcd(a,b),则a'=2k,b'=2k+1(k为正整数)。那么只要枚举最大公约数t,然后构造(mt)和(m+1)t,然后测试(mt)xor(m+1)t==t就行了。
/*
* Author: Joshua
* Created Time: 2014年10月05日 星期日 20时36分26秒
* File Name: h.cpp
*/
#include<cstdio>
#define maxn 30000001
int f[maxn];
int n,T; void solve()
{
for (int i=;i<maxn;++i)
for (int j=i+i;j<maxn;j+=i)
if ((j^(j-i))==i) f[j]++;
for (int i=;i<maxn;++i)
f[i]+=f[i-];
} int main()
{
solve();
scanf("%d",&T);
int x;
for (int i=;i<=T;++i)
{
scanf("%d",&x);
printf("Case %d: %d\n",i,f[x]);
}
return ;
}
uval 6657 GCD XOR的更多相关文章
- uvalive 6657 GCD XOR
//感觉太长时间没做题 好多基本的能力都丧失了(>_<) 首先大概是这样的,因为gcd(a,b)=c,所以a,b都是c的倍数,所以我们依次枚举a的值为2c 3c 4c......,a xo ...
- UVa 12716 && UVaLive 6657 GCD XOR (数论)
题意:给定一个 n ,让你求有多少对整数 (a, b) 1 <= b <= a 且 gcd(a, b) = a ^ b. 析:设 c = a ^ b 那么 c 就是 a 的约数,那么根据异 ...
- GCD XOR uvalive6657
GCD XORGiven an integer N, nd how many pairs (A; B) are there such that: gcd(A; B) = A xor B where1 ...
- UVA.12716 GCD XOR (暴力枚举 数论GCD)
UVA.12716 GCD XOR (暴力枚举 数论GCD) 题意分析 题意比较简单,求[1,n]范围内的整数队a,b(a<=b)的个数,使得 gcd(a,b) = a XOR b. 前置技能 ...
- GCD XOR UVA 12716 找规律 给定一个n,找多少对(a,b)满足1<=b<=a<=n,gcd(a,b)=a^b;
/** 题目:GCD XOR UVA 12716 链接:https://vjudge.net/problem/UVA-12716 题意:给定一个n,找多少对(a,b)满足1<=b<=a&l ...
- UVa 12716 (GCD == XOR) GCD XOR
题意: 问整数n以内,有多少对整数a.b满足(1≤b≤a)且gcd(a, b) = xor(a, b) 分析: gcd和xor看起来风马牛不相及的运算,居然有一个比较"神奇"的结论 ...
- GCD XOR(UVa 12716)
题意:输入整数n(1<=n<=30000000),有多少对整数(a,b)满足1<=b<=a<=n,且gcd(a,b)=a xor b. 题解:设c=gcd(a,b),因为 ...
- UVa 12716 - GCD XOR(筛法 + 找规律)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA 12716 GCD XOR
https://vjudge.net/problem/UVA-12716 求有多少对整数(a,b)满足:1<=b<=a<=n,且gcd(a,b)=a XOR b 结论:若gcd(a, ...
随机推荐
- new DefaultHttpClient过时处理建议和HTTP调用后关闭流处理
因为工作中经常会写点接口类需求,写完HTTP的接口后,就要写测试类来调下服务端的代码.最近写新的测试调用代码时候,发现项目中new DefaultHttpClient()实例过期很久了,于是查阅了些资 ...
- 【Spring】关于SpringMvc监听的知识点
一,在使用Spring系列框架时,我们需要在Web.xml配置Spring的监听:ContextLoaderListener ContextLoaderListener的作用就是,在Web容器初始化时 ...
- 利用Unity3D与Oculus实现机器情绪安抚师的一种方案
(一张最原始的Unity3D中音乐可视化粒子海的图,想象一下,如果这幅场景出现在虚拟设备中,辅以根据音乐频谱变化的色彩与悦动频率,会是怎样的效果呢?) Unity3D有着非常完备的虚拟三维场景交互开发 ...
- macOS下配置scapy环境
测试需求需要用到scapy库,遂在本机配置scapy环境,但最后一直提示权限问题,可能和sip有关系. 最后在同事介绍下使用虚拟环境(virtualenv)搞定. virtualenv: Virtua ...
- 使用jquery获取url及url参数的方法
使用jquery获取url以及使用jquery获取url参数是我们经常要用到的操作 1.jquery获取url很简单,代码如下: window.location.href; 其实只是用到了javasc ...
- Angular2 VS Angular4 深度对比:特性、性能
欢迎大家持续关注葡萄城控件技术团队博客,更多更好的原创文章尽在这里~~ 在Web应用开发领域,Angular被认为是最好的开源JavaScript框架之一. Google的Angular团队已于3月 ...
- Web安全测试——威胁攻防
SQL注入 部分程序员在编写代码的时候,没有对用户输入数据的合法性进行判断,使应用程序存在安全隐患.用户可以提交一段数据库查询代码,根据程序返回的结果,获得某些他想得知的数据,这就是所谓的SQL In ...
- Log4net快速配置使用指南。(快速搭建log4net日志平台手册)
每做一个新项目,都会用到log4net,但总是忘记如何快速配置.有时在网上搜半天也找不到好的模板,大都在介绍参数的使用,在此做下总结,争取下次用时仅10分钟就可搭建好log4net. 直接上介绍的步骤 ...
- wpf mvvm datagrid DataGridTemplateColumn的绑定无效的可能原因之一!
昨天在mvvm wpf的开发中遇到一个问题,绑定不起作用,编辑阶段没问题也没有提示找不到对应的绑定,但是在运行之后却不起作用,查了很多资料,说法不一,有些是要删除datagrid的一行,直接绑定del ...
- C#调用C++数据类型对照
类型对照: BSTR --------- StringBuilder LPCTSTR --------- StringBuilder LPCWSTR --------- IntPtr handle-- ...