HDU 5175
我想了很久了,后来还是把N分解质因数,枚举各种组合,反正也不多吧,按题目条件,然后就过了。
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cctype>
#include <algorithm>
#define LL __int64
using namespace std; LL prime[100010],np;
int fac[100010],nf;
int cnt,nop;
struct Node{
LL f;
int cnt;
}node[100100];
LL ans[100010]; void predo(LL n){
np=0;
bool isprime[100010];
memset(isprime,false,sizeof(isprime));
for(LL i=2;i<=n;i++){
if(!isprime[i]){
isprime[i]=true;
prime[np++]=i;
for(LL j=i*i;j<=n;j+=i)
isprime[j]=true;
}
}
} bool Isprime(LL n){
nf=0;
for(LL i=0;i<np&&prime[i]<=n;i++){
if(n%prime[i]==0){
while(n%prime[i]==0){
fac[nf++]=prime[i];
n/=prime[i];
}
}
}
if(n!=1){
fac[nf++]=n;
}
if(nf<=1) return true;
return false;
} LL GCD(LL a,LL b){
if(b==0) return a;
return GCD(b,a%b);
} void dfs(LL n,int pos,LL gcd){
if(pos==nop+1){
LL x=n^gcd;
if(x>=n) return ;
if(x==0) return ;
if(gcd==GCD(n,x))
ans[cnt++]=x;
return ;
}
for(int i=0;i<=node[pos].cnt;i++){
if(i==0){
dfs(n,pos+1,gcd);
}
else{
gcd*=node[pos].f;
dfs(n,pos+1,gcd);
}
}
} int main(){
int t=0;
LL n;
predo(100010LL);
while(scanf("%I64d",&n)!=EOF){
if(n==1LL||n==2){
printf("Case #%d:\n",++t);
puts("0");
puts("");
continue;
}
if(Isprime(n)){
printf("Case #%d:\n",++t);
puts("1");
printf("%I64d\n",n-1);
}
else{
nop=-1;
for(int i=0;i<nf;i++){
if(i==0||fac[i]!=fac[i-1]){
node[++nop].f=fac[i];
node[nop].cnt=1;
}
else
node[nop].cnt++;
} cnt=0;
dfs(n,0,1LL);
sort(ans,ans+cnt);
printf("Case #%d:\n",++t);
printf("%d\n",cnt);
if(cnt==0){
puts("");
continue;
}
printf("%I64d",ans[0]);
for(int i=1;i<cnt;i++){
printf(" %I64d",ans[i]);
}
printf("\n");
}
}
return 0;
}
HDU 5175的更多相关文章
- hdu 5175(数论)
Misaki's Kiss again Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- hdu 5175 Misaki's Kiss again
Misaki's Kiss again Accepts: 75 Submissions: 593 Time Limit: 2000/1000 MS (Java/Others) Memory L ...
- hdu 5175 Misaki's Kiss again(GCD和异或)
题意: 给一个数N. 如果GCD(N,M) = N XOR M,则称M是一个kiss 1<=M<=N 问总共有多少个kiss.并且列出所有的值. 思路: 思路一:枚举M.有大量的GCD ...
- BestCoder Valentine's Day Round
昨晚在开赛前5分钟注册的,然后比赛刚开始就掉线我就不想说了(蹭网的下场……),只好用手机来看题和提交,代码用电脑打好再拉进手机的(是在傻傻地用手机打了一半后才想到的办法). 1001,也就是 hdu ...
- Valentine's Day Round hdu 5176 The Experience of Love [好题 带权并查集 unsigned long long]
传送门 The Experience of Love Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Ja ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
随机推荐
- 【POJ 1456】 Supermarket
[题目链接] http://poj.org/problem?id=1456 [算法] 贪心 + 堆 [代码] #include <algorithm> #include <bitse ...
- B3680 吊打xxx 物理???
看到一道很有意思的题,这个题简直有毒,是一道物理题...好像得用模拟退火...但显然我太弱了不会模拟退火,只能用正交分解暴力... 每次沿着力的方向走一定的距离,假如转头了,则走的步长就减小一点. 不 ...
- 部署webservice常见问题汇总
问题一 转自http://blog.csdn.net/xingxing513234072/article/details/38615997 处理程序“WebServiceHandlerFactory- ...
- Tunnel Warfare(树状数组+二分)
http://poj.org/problem?id=2892 题意:输入n,m.n代表数轴的长度,m代表操作数. D x: 摧毁点x Q x: 询问村庄x最左与最右没有被摧毁的点的距离 R :恢复最 ...
- yii的criteria的用法
Yii的Active Recorder包装了很多. 特别是把SQL中 把where,order,limit,IN/not IN,like等常用短句都包含进CDbCriteria这个类中去,这样整个代码 ...
- sublime text 快键键
sublime text 的快捷键ctrl+l 选择整行(按住-继续选择下行)ctrl+shift+k ...
- MySql c#通用类
using System; using System.Collections.Generic; using System.Linq; using System.Text;//导命名空间 using S ...
- BootStrap 资源包的下载和使用
将附件中的包解压,放置webroot中,并在jsp页面中引用它们,即可以使用 bootstrap.rar (78.9 KB) 下载次数: 0
- W3C标准冒泡、捕获机制
(一) 捕获和冒泡如何相互影响 我们来做几个任务吧! 有一个前提,#parent为标签,#child为子标签,他们是嵌套关系支线任务1 //捕获模式 document.getElementById(' ...
- Excel的用到的常规的技巧
这几天在做各种发票的报表,好几百的数据当然离不开EXCel,自己又是个白班,就记录下啦! EXCEL 判断某一单元格值是否包含在某一列中 就在Excel的表格中加入这个函数:=IF(ISERROR(V ...