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的更多相关文章

  1. uvalive 6657 GCD XOR

    //感觉太长时间没做题 好多基本的能力都丧失了(>_<) 首先大概是这样的,因为gcd(a,b)=c,所以a,b都是c的倍数,所以我们依次枚举a的值为2c 3c 4c......,a xo ...

  2. UVa 12716 && UVaLive 6657 GCD XOR (数论)

    题意:给定一个 n ,让你求有多少对整数 (a, b) 1 <= b <= a 且 gcd(a, b) = a ^ b. 析:设 c = a ^ b 那么 c 就是 a 的约数,那么根据异 ...

  3. 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 ...

  4. UVA.12716 GCD XOR (暴力枚举 数论GCD)

    UVA.12716 GCD XOR (暴力枚举 数论GCD) 题意分析 题意比较简单,求[1,n]范围内的整数队a,b(a<=b)的个数,使得 gcd(a,b) = a XOR b. 前置技能 ...

  5. 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 ...

  6. UVa 12716 (GCD == XOR) GCD XOR

    题意: 问整数n以内,有多少对整数a.b满足(1≤b≤a)且gcd(a, b) = xor(a, b) 分析: gcd和xor看起来风马牛不相及的运算,居然有一个比较"神奇"的结论 ...

  7. GCD XOR(UVa 12716)

    题意:输入整数n(1<=n<=30000000),有多少对整数(a,b)满足1<=b<=a<=n,且gcd(a,b)=a xor b. 题解:设c=gcd(a,b),因为 ...

  8. UVa 12716 - GCD XOR(筛法 + 找规律)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  9. UVA 12716 GCD XOR

    https://vjudge.net/problem/UVA-12716 求有多少对整数(a,b)满足:1<=b<=a<=n,且gcd(a,b)=a XOR b 结论:若gcd(a, ...

随机推荐

  1. 玩玩微信公众号Java版之六:微信网页授权

    我们经常会访问一些网站,用微信登录的时候需要用到授权,那么微信网页授权是怎么一回事呢,一起来看看吧!   参考官方文档:https://mp.weixin.qq.com/wiki?t=resource ...

  2. 【菜鸟入门】安装配置eclipse 并编写运行第一个Java程序

    不得不吐槽一下,安装配置这eclipse真是太费劲了...下面总结一下,以便下次再安装 本人 win10系统,64位机 一.在官网下载eclipse安装包 文件名:eclipse-inst-win64 ...

  3. poj_2104: K-th Number 【主席树】

    题目链接 学习了一下主席树,感觉具体算法思路不大好讲.. 大概是先建个空线段树,然后类似于递推,每一个都在前一个"历史版本"的基础上建立一个新的"历史版本",每 ...

  4. public/private/protected的具体区别

    在说明这四个关键字之前,我想就class之间的关系做一个简单的定义,对于继承自己的class,base class可以认为他们都是自己的子女,而对于和自己一个目录下的classes,认为都是自己的朋友 ...

  5. (转)java并发之Executor

    场景: 线程池在面试时候经常会碰到,在工作中用的场景更多,所以很有必要弄清楚. 1 简介 Java自1.5以来加入了处理一批线程的方法,也就是java并发包里的Executor.本文主要介绍Execu ...

  6. (转)OGNL表达式介绍

    OGNL是Object-Graph Navigation Language的缩写,它是一种功能强大的表达式语言(Expression Language,简称为EL),通过它简单一致的表达式语法,可以存 ...

  7. echarts_部分图表配置_堆叠折线图

    echarts基本图表使用: 1.获取包裹元素(var myChart = echarts.init(document.getElementById('thisId'));)2.设置option(op ...

  8. Java之线程,常用方法,线程同步,死锁

    1, 线程的概念 进程与线程 进程:每个进程都有独立的代码和数据空间(进程上下文),进程间的切换会有较大的开销,一个进程包含1--n个线程.(进程是资源分配的最小单位) 线程:同一类线程共享代码和数据 ...

  9. [POI2008]枪战Maf

    [POI2008]枪战Maf 题目 有n个人,每个人手里有一把手枪.一开始所有人都选定一个人瞄准(有可能瞄准自己).然后他们按某个顺序开枪,且任意时刻只有一个人开枪.因此,对于不同的开枪顺序,最后死的 ...

  10. vc操作电脑之常用命令

    1.重启计算机: ExitWindowsEx(EWX_REBOOT,0); 2.关机: ExitWindowsEx(EWX_SHUTDOWN,0); 3.注销: ExitWindowsEx(EWX_L ...