题目:UVA12716

题意:  问 gcd(i,j) = i ^ j  的对数(j <=i <= N ) N的范围为30000000,有10000组样例

分析:

 有几个结论:(1)若 a xor b = c,则 a xor c = b。

        (2)a - b <= a xor b,(a >= b)

        (3)若 gcd(a,b)= a xor b = c ,(a >= b),由(2)得:a - b <= c。

            再令 a = k1×c,b = k2 × c,(k1 >= k2),所以 a - b = (k1 - k2)× c,所以 a - b >= c。总:a - b = c

           (这里若k1 = k2,那么 a = b,那么 a xor b = 0)

  然后就是怎么枚举的问题了,要保证计算量尽量小,如果枚举a,就要枚举a的所有因数,有些数因为可能是多个数的因数,会被重复考虑很多次。所以这里要枚举因数 c ,a = k × c(k >= 2) 这样每个因数只枚举一遍,再检验b。

代码:

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
const int maxm=3e7+;
int s[maxm];
void init()
{
for(int c=;c<maxm/;c++)
{
for(int a=c+c;a<maxm;a+=c)
{
int b=a-c;
if((a^b)==c)
s[a]++;
}
}
for(int i=;i<maxm;i++)
s[i]+=s[i-];
}
int main()
{
int t;
scanf("%d",&t);
int k=;
init();
while(t--)
{
int n;
scanf("%d",&n);
printf("Case %d: %d\n",++k,s[n]);
}
}

GCD 与XOR的更多相关文章

  1. D. Kuro and GCD and XOR and SUM

    Kuro is currently playing an educational game about numbers. The game focuses on the greatest common ...

  2. CF 979D Kuro and GCD and XOR and SUM(异或 Trie)

    CF 979D Kuro and GCD and XOR and SUM(异或 Trie) 给出q(<=1e5)个操作.操作分两种,一种是插入一个数u(<=1e5),另一种是给出三个数x, ...

  3. CodeForces979D:Kuro and GCD and XOR and SUM(Trie树&指针&Xor)

    Kuro is currently playing an educational game about numbers. The game focuses on the greatest common ...

  4. CodeForces 979 D Kuro and GCD and XOR and SUM

    Kuro and GCD and XOR and SUM 题意:给你一个空数组. 然后有2个操作, 1是往这个数组里面插入某个值, 2.给你一个x, k, s.要求在数组中找到一个v,使得k|gcd( ...

  5. Codeforces 979 D. Kuro and GCD and XOR and SUM(异或和,01字典树)

    Codeforces 979 D. Kuro and GCD and XOR and SUM 题目大意:有两种操作:①给一个数v,加入数组a中②给出三个数x,k,s:从当前数组a中找出一个数u满足 u ...

  6. codeforces 979D Kuro and GCD and XOR and SUM

    题意: 给出两种操作: 1.添加一个数字x到数组. 2.给出s,x,k,从数组中找出一个数v满足gcd(x,k) % v == 0 && x + v <= s && ...

  7. Codeforces Round #482 (Div. 2) : Kuro and GCD and XOR and SUM (寻找最大异或值)

    题目链接:http://codeforces.com/contest/979/problem/D 参考大神博客:https://www.cnblogs.com/kickit/p/9046953.htm ...

  8. 题解 UVA12716 GCD等于XOR GCD XOR

    规律题,打表找规律即可发现 a xor b >= a - b >= gcd(a, b), 如果 a xor b = gcd(a, b) = c 则 c = a - b 枚举倍数c和a判断b ...

  9. UVA - 12716 GCD XOR(GCD等于XOR)(数论)

    题意:输入整数n(1<=n<=30000000),有多少对整数(a, b)满足:1<=b<=a<=n,且gcd(a,b)=a XOR b. 分析:因为c是a的约数,所以枚 ...

随机推荐

  1. vue动态组件 互相之间传输数据 和指令的定义

    地址:https://blog.csdn.net/zhanghuanhuan1/article/details/77882595 地址:https://www.cnblogs.com/xiaohuoc ...

  2. python基础--快速排序

    1.快速排序 快速排序是一种交换排序. 快速排序由C. A. R. Hoare在1962年提出. 它的基本思想是:通过一趟排序将要排序的数据分割成独立的两部分:分割点左边都是比它小的数,右边都是比它大 ...

  3. rabbitmq-5-案例2-简单的案例+exchange

    Exchange交换机: sendMessage端,发送消息到Exchage1.2, 然后交换机通过路由键,将消息转发给队列queue中,最后客户端从队列中获取消息 交换属性: name:名称 typ ...

  4. 小程序中使用async函数 会报 regeneratorRuntime is not defined的问题

    async await比Promise更好的解决异步操作问题,但是在小程序中直接使用会出现以下的错误提示 是因为缺少了regeneratorRuntime这个模块,需要从外部引入 1.在新建的文件夹中 ...

  5. 【转载】MySQL查询当天0点,昨天时间

    转载自:https://blog.csdn.net/qq_22158021/article/details/78800299 今天是 SELECT NOW();-- 2015-09-28 13:48: ...

  6. 2019-10-31-WPF-等距布局

    title author date CreateTime categories WPF 等距布局 lindexi 2019-10-31 9:0:2 +0800 2018-2-21 17:3:4 +08 ...

  7. 2018-2-13-win10-UWP-应用设置

    title author date CreateTime categories win10 UWP 应用设置 lindexi 2018-2-13 17:23:3 +0800 2018-2-13 17: ...

  8. crontab+selenium不能定时执行测试的原因

    上一篇我提到用无界面selenium实现网页的自动签到.本来测试好好 的没问题,但是加进crontab定时任务却一点动静页没有,后来发现是浏览器的显示问题,自动任务要这样写: 12 3 * * * e ...

  9. NFS 共享存储实战

    目录 NFS 共享存储实战 一.NFS概述 二.NFS部署 部署NFS客户端backup和web01 统一web.nfs.backup的用户权限 代码部署步骤 三.NFS配置详解 NFS存储小结 四. ...

  10. linux随笔-01

    认识linux 开源共享精神 低风险 高品质 低成本 更透明 开源软件的特点 使用自由.修改自由.传播自由.收费自由以及创建衍生品的自由 常见的开源许可协议 GNU GPL(GNU General P ...