uva12716GCD XOR
筛法,打表。
通过打表可知,但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的更多相关文章
- [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 ...
- 二分+DP+Trie HDOJ 5715 XOR 游戏
题目链接 XOR 游戏 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- BZOJ 2115 【Wc2011】 Xor
Description Input 第一行包含两个整数N和 M, 表示该无向图中点的数目与边的数目. 接下来M 行描述 M 条边,每行三个整数Si,Ti ,Di,表示 Si 与Ti之间存在 一条权值为 ...
- xor和gates的专杀脚本
前段时间的一次样本,需要给出专杀,应急中遇到的是linux中比较常见的两个家族gates和xor. 首先是xor的专杀脚本,xor样本查杀的时候需要注意的是样本的主进程和子进程相互保护(详见之前的xo ...
- Codeforces617 E . XOR and Favorite Number(莫队算法)
XOR and Favorite Number time limit per test: 4 seconds memory limit per test: 256 megabytes input: s ...
- Xor && 线性基练习
#include <cstdio> #include <cstring> ; ; int cnt,Ans,b,x,n; inline int Max(int x,int y) ...
- BC之Claris and XOR
http://acm.hdu.edu.cn/showproblem.php?pid=5661 Claris and XOR Time Limit: 2000/1000 MS (Java/Others) ...
- 异或链表(XOR linked list)
异或链表(Xor Linked List)也是一种链式存储结构,它可以降低空间复杂度达到和双向链表一样目的,任何一个节点可以方便的访问它的前驱节点和后继结点.可以参阅wiki 普通的双向链表 clas ...
- hdu 5661 Claris and XOR
Claris and XOR Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
随机推荐
- SQL Server表分区【转】
转自:http://www.cnblogs.com/knowledgesea/p/3696912.html SQL Server表分区 什么是表分区 一般情况下,我们建立数据库表时,表数据都存放在 ...
- Eclipse 创建Maven工程
前言 开发环境 sts-3.7.2.RELEASE 创建步骤 1.开启eclipse,右键new——>other,如下图找到maven project 2.选择maven project,显示创 ...
- 【BZOJ】【1026】【SCOI2009】Windy数
数位DP cxlove基础数位DP第三题 = =预处理是个很有用的东西!然后就是分类讨论! /***************************************************** ...
- [转载]C#中的WebBrowser控件的使用
http://www.cnblogs.com/txw1958/archive/2012/09/24/CSharp-WebBrowser.html
- DelayedOperationPurgatory之purgatory的实现
purgatory的超时检测 当一个DelayedOpeartion超时(timeout)时,它需要被检测出来,然后调用它的回调方法.这个事情看起来很简单,但做好也并不容易. 0.8.x的Kafka的 ...
- list 去掉重复的值
去除List列表中重复值(3种解决方法)public static void main(String[] args) { String[] ar = { "dd", "c ...
- 【leetcode】Add Two Numbers(middle) ☆
You are given two linked lists representing two non-negative numbers. The digits are stored in rever ...
- the-type-java-lang-charsequence-cannot-be-resolved-in-package-declaration
http://stackoverflow.com/questions/24301986/the-type-java-lang-charsequence-cannot-be-resolved-in-pa ...
- C# MessageBox 用法大全(转)
C# MessageBox 用法大全 http://www.cnblogs.com/Tammie/archive/2011/08/05/2128623.html 我们在程序中经常会用到MessageB ...
- HDU 1452 Happy 2004(因子和的积性函数)
题目链接 题意 : 给你一个X,让你求出2004的X次方的所有因子之和,然后对29取余. 思路 : 原来这就是积性函数,点这里这里这里,这里讲得很详细. 在非数论的领域,积性函数指所有对于任何a,b都 ...