Misaki's Kiss again

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1773    Accepted Submission(s): 459

After the Ferries Wheel, many friends hope to receive the Misaki's kiss again,so Misaki numbers them 1,2...N−1,N,if someone's number is M and satisfied the GCD(N,M) equals to N XOR M,he will be kissed again.

Please help Misaki to find all M(1<=M<=N).

Note that:
GCD(a,b) means the greatest common divisor of a and b.
A XOR B means A exclusive or B
 

B

Input
There are multiple test cases.

For each testcase, contains a integets N(0<N<=1010)
 
Output
For each test case,
first line output Case #X:,
second line output k means the number of friends will get a kiss.
third line contains k number mean the friends' number, sort them in ascending and separated by a space between two numbers
 
Sample Input
3
5
15
Sample Output
Case #1:
1
2
Case #2:
1
4
Case #3:
3
10 12 14
思路:gcd(n,m) = norm --->gcd(n,nork) =  k;应为m 可以表示为nork的形式,所以,我们只要枚举n的因子k然后判断是否符合即可。
 1 #include<stdio.h>
2 #include<algorithm>
3 #include<iostream>
4 #include<string.h>
5 #include<math.h>
6 #include<queue>
7 #include<stdlib.h>
8 #include<set>
9 #include<vector>
10 using namespace std;
11 typedef long long LL;
12 LL ans[100000];
13 LL gcd(LL n,LL m);
14 int main(void)
15 {
16 LL N;
17 int cn = 0;
18 while(scanf("%lld",&N)!=EOF)
19 {
20 cn++;
21 ans[0] = -1;
22 printf("Case #%d:\n",cn);
23 if(N == 1)
24 {
25 printf("0\n");
26 printf("\n");
27 }
28 else
29 {
30 int sum = 0;
31 LL i;
32 for(i = 1; i <= sqrt(N); i++)
33 {
34 if(N%i==0)
35 {
36 LL pp = gcd(N,(LL)(N/(LL)i-(LL)1)*(LL)(i));
37 LL ac = N^((LL)(N/(LL)i-(LL)1)*(LL)(i));
38 if((N/i-1>=1)&&pp == ac)
39 {
40 ans[sum++] = (LL)(N/(LL)i-(LL)1)*(LL)(i);
41 }
42 if(N/(LL)i!=i)
43 {
44 LL pp = gcd(N,(LL)(i-1)*(LL)(N/i));
45 LL ac = (LL)(i-1)*(LL)(N/i)^N;
46 if(i-1>0&&ac == pp)
47 {
48 //printf("1\n");
49 ans[sum++] = (LL)(i-1)*(LL)(N/i);
50 }
51 }
52 }
53 }
54 printf("%d\n",sum);
55 sort(ans,ans+sum);
56 if(sum>=1)
57 printf("%lld",ans[0]);
58 for(i = 1; i < sum; i++)
59 {
60 printf(" %lld",ans[i]);
61 }
62 printf("\n");
63 }
64 }
65 return 0;
66 }
67 LL gcd(LL n,LL m)
68 {
69 if(m == 0)
70 return n;
71 else return gcd(m,n%m);
72 }

最新文章

  1. JDK环境变量设置
  2. 科普:浅谈 Hellinger Distance
  3. UVA 11090 Going in Cycle!!(二分答案+判负环)
  4. ios7 sdk 新特性
  5. Mybatis高级应用
  6. LeetCode(4) || Longest Palindromic Substring 与 Manacher 线性算法
  7. SNMP PDU解析
  8. 有关linux下redis overcommit_memory的问题
  9. ACE在windows下的编译及配置(VS2010)
  10. 使用cookie来做身份认证
  11. 深入浅出KNN算法(二) sklearn KNN实践
  12. Linux桌面系统常用软件和笔记(更新)
  13. 出现No package gcc+ available解决办法
  14. 爬虫之urllib
  15. swift 导入 .a 和 .h 文件
  16. 接上篇,php生成静态页面,加上页面时间缓存
  17. echarts中间有字饼图Demo2
  18. 实验4 IIC通讯与EEPROM接口
  19. 安卓开发笔记①:利用高德地图API进行定位、开发电子围栏、天气预报、轨迹记录、搜索周边(位置)
  20. iOS开发之地域选择

热门文章

  1. 也谈string.Join和StringBuilder的性能比较
  2. mybatis项目中,使用useSSL=true却报错
  3. Java 数据类型转化
  4. SQLITE_BTREE_H
  5. absurd, abundant
  6. 零基础学习java------day17------缓冲字节流,转换字节流,简化流,缓冲字符流,序列化和对象流
  7. tomcat启动和停止脚本
  8. 【Linux】【Shell】【Basic】一行代码解决常见问题
  9. OpenStack之之一: 快速添加计算节点
  10. 全网最详细的AbstractQueuedSynchronizer(AQS)源码剖析(一)AQS基础