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 ...
随机推荐
- B5090 组题 二分答案
bzoj有毒,看不了自己哪错了...根本没法debug. 我到现在还是不知道自己代码为什么会T,二分次数也加限制了,但是还是T...救命啊!!! 题干: Description 著名出题人小Q的备忘录 ...
- web认证方案
web构建在http之上,而它又是无状态协议,如何控制用户访问服务器上的受限资源呢? 最原始你想法通过http基本认证,每次发请求时都向后台传递用户名密码信息,服务器每次收到请求后都先验证用户是否合法 ...
- C# Task 源代码阅读(2)
上篇已经讲到Task 的默认的TaskScheduler 为ThreadPoolTaskScheduler. 这时我们回到原来的task 的start方法,在代码最后,调用了 ScheduleAndS ...
- google搜索引擎使用方法
搜索引擎命令大全!这是一个我最喜欢的Google搜索技巧的清单: link:URL = 列出到链接到目标URL的网页清单. related:URL = 列出于目标URL地址有关的网页. site:ht ...
- Spring配置事务中的 transactionAttributes 各属性含义及XML配置
转自:https://blog.csdn.net/z69183787/article/details/17161393 transactionAttributes 属性: PROPAGATION 事务 ...
- 后台传list,前台接受
@RequestMapping("/page1") public ModelAndView editSharing(Integer id) { ModelAndView mav=n ...
- Win7的虚拟Wi-Fi
前几天无意中发现,Win7的硬件驱动里有个叫Microsoft Virtual WiFi Miniport Adapter的东东,从网上查了一下,可以用来组建临时网络,共享Internet.一块无线网 ...
- 阿里云 CentOS 6.5 使用XAMPP 搭建LAMP环境
LAMP环境是常见的服务器环境,也是PHP网站常用的服务器环境,很多人喜欢手动配置,但是手动配置LAMP复杂.麻烦,简单一点的话可以使用集成环境.试了下LNMP的集成环境,用不习惯,另外由于本地一直使 ...
- Windows7环境下Composer 安装包的Cache目录位置
http://segmentfault.com/a/1190000000355928 https://getcomposer.org/doc/ 要说Composer的用法,以后再说,现在只记录wind ...
- 【JAVA练习】- 给定精度求圆周率π
给定一个精度求圆周率π的近似值 给定公式:π/4=1-1/3+1/5-1/7+1/9-... public static void main(String[] args) { System.out.p ...