筛法,打表。

通过打表可知,但gcd(a,b)==a xor b时,a xor b = a-b.

就是求满足 c = a-b且c = a xor b 的c的个数。

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn = 30000000; int ans[maxn+10];
int a,b,c,n;
int T; void init() {
int data=maxn>>1;
memset(ans,0,sizeof(ans));
for(int c=1;c<=data;c++)
for(int a=c*2;a<=maxn;a+=c) {
b=a-c;
if((a^b)==c) ans[a]++;
}
for(int i=2;i<=maxn;i++) ans[i]+=ans[i-1];
} int main() {
init();
scanf("%d",&T);
for(int i=1;i<=T;i++) {
scanf("%d",&n);
printf("Case %d: %d\n",i,ans[n]);
}
return 0;
}

uva12716GCD XOR的更多相关文章

  1. [LeetCode] Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字

    Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...

  2. 二分+DP+Trie HDOJ 5715 XOR 游戏

    题目链接 XOR 游戏 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  3. BZOJ 2115 【Wc2011】 Xor

    Description Input 第一行包含两个整数N和 M, 表示该无向图中点的数目与边的数目. 接下来M 行描述 M 条边,每行三个整数Si,Ti ,Di,表示 Si 与Ti之间存在 一条权值为 ...

  4. xor和gates的专杀脚本

    前段时间的一次样本,需要给出专杀,应急中遇到的是linux中比较常见的两个家族gates和xor. 首先是xor的专杀脚本,xor样本查杀的时候需要注意的是样本的主进程和子进程相互保护(详见之前的xo ...

  5. Codeforces617 E . XOR and Favorite Number(莫队算法)

    XOR and Favorite Number time limit per test: 4 seconds memory limit per test: 256 megabytes input: s ...

  6. Xor && 线性基练习

    #include <cstdio> #include <cstring> ; ; int cnt,Ans,b,x,n; inline int Max(int x,int y) ...

  7. BC之Claris and XOR

    http://acm.hdu.edu.cn/showproblem.php?pid=5661 Claris and XOR Time Limit: 2000/1000 MS (Java/Others) ...

  8. 异或链表(XOR linked list)

    异或链表(Xor Linked List)也是一种链式存储结构,它可以降低空间复杂度达到和双向链表一样目的,任何一个节点可以方便的访问它的前驱节点和后继结点.可以参阅wiki 普通的双向链表 clas ...

  9. hdu 5661 Claris and XOR

    Claris and XOR Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

随机推荐

  1. 屏蔽ios7中某个页面的默认手势滑回返回

    - (void)viewWillDisappear:(BOOL)animated {[super viewWillDisappear:YES];self.navigationController.in ...

  2. SharePoint 优化显示WebParts

    在开发sharepoint中,经常遇到需要自定义显示列表中的一部分作为导航的内容, 如公告栏,新闻链接,最新动态等.... 我们通常需要显示一个列表的标题,并且限制字符长度, 外加一些条件,如按创建的 ...

  3. sed 详解

    sed 详解 1.简介 sed是非交互式的编辑器.它不会修改文件,除非使用shell重定向来保存结果.默认情况下,所有的输出行都被打印到屏幕上. sed编辑器逐行处理文件(或输入),并将结果发送到屏幕 ...

  4. hibernate4.0中SessionFactory的创建

    创建SessionFactory 首先创建Configuration对象,主要方式是: new Configuration().configure() 默认情况下Hibernate会去classPat ...

  5. uva 10912

    dp 记忆化搜索 #include <cstdio> #include <cstdlib> #include <cmath> #include <map> ...

  6. Google 网站打不开

    http://209.116.186.246/ http://91.213.30.153/  (2014年6月30日 新增) https://wen.lu/ (2014年6月30日 新增,注意下是ht ...

  7. 国内最大的 Node.js 社区将 New Relic 的监控产品换成了 OneAPM

    国内最知名的 CNode 社区把 New Relic 的监控产品换成了 OneAPM .难道 APM 的老大 New Relic 已经被 OneAPM 超越? 毋庸置疑,在全球应用性能管理 SaaS ...

  8. JavaScript Madness: Dynamic Script Loading

    Introduction I've developed some pretty seriously Javascript intensive sites, where the sheer quanti ...

  9. Project Euler 84:Monopoly odds 大富翁几率

    Monopoly odds In the game, Monopoly, the standard board is set up in the following way:             ...

  10. [z]CAP原理和BASE思想

    分布式领域CAP理论,Consistency(一致性), 数据一致更新,所有数据变动都是同步的Availability(可用性), 好的响应性能Partition tolerance(分区容错性) 可 ...