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 }

Misaki's Kiss again(hdu5175)的更多相关文章

  1. hdu 5175 Misaki's Kiss again(GCD和异或)

    题意: 给一个数N. 如果GCD(N,M) = N XOR M,则称M是一个kiss   1<=M<=N 问总共有多少个kiss.并且列出所有的值. 思路: 思路一:枚举M.有大量的GCD ...

  2. Form验证(转)

    代码写 N 久了,总想写得别的.这不,上头说在整合两个项目,做成单一登录(Single Sign On),也有人称之为“单点登录”.查阅相关文档后,终于实现了,现在把它拿出来与大家一起分享.或许大家会 ...

  3. 跟我一起云计算(5)——Shards

    什么是sharding Sharding的基本思想就要把一个数据库切分成多个部分放到不同的数据库 (server)上,从而缓解单一数据库的性能问题.不太严格的讲,对于海量数据的数据库,如果是因为表多而 ...

  4. Angular(1)

    1.设计原则 1.YAGNI  不要把未来需求引入当前工程   2.KISS  keep it simple and stupid  语义化标记 合理注释 符合规定的命名 3.DRY(don't re ...

  5. 你应当如何学习C++(以及编程)(转载)

    你应当如何学习C++(以及编程)(rev#1) By 刘未鹏(pongba) C++的罗浮宫(http://blog.csdn.net/pongba) Javascript是世界上最受误解的语言,其实 ...

  6. 【转】理解依赖注入(IOC)和学习Unity

    IOC:英文全称:Inversion of Control,中文名称:控制反转,它还有个名字叫依赖注入(Dependency Injection).作用:将各层的对象以松耦合的方式组织在一起,解耦,各 ...

  7. 理解依赖注入(IOC)和学习Unity

    资料1: IOC:英文全称:Inversion of Control,中文名称:控制反转,它还有个名字叫依赖注入(Dependency Injection). 作用:将各层的对象以松耦合的方式组织在一 ...

  8. [欢度国庆]为什么我们今天还要学习和使用C++?(转载)

    在各种新的开发语言层出不穷的今天,在Java和C#大行其道今天,我们为什么还要学习和使用C++?现在学习C++将来有用吗?学习C++要花费那么多时间和精力,这一切都值得吗?现在学习C++有钱途吗? 这 ...

  9. 对面向对象程序设计(OOP)的认识

    前言 本文主要介绍面向对象(OO)程序设计,以维基百科的解释: 面向对象程序设计(英语:Object-oriented programming,缩写:OOP),指一种程序设计范型,同时也是一种程序开发 ...

随机推荐

  1. 字符scanf 的输入注意

    1.注意scanf 不能有空格,如果有空格会将空格给输入进去 scanf("d "):---有空格 和scanf("d");--没有空格 有很大的区别

  2. Identity Server 4 从入门到落地(四)—— 创建Web Api

    前面的部分: Identity Server 4 从入门到落地(一)-- 从IdentityServer4.Admin开始 Identity Server 4 从入门到落地(二)-- 理解授权码模式 ...

  3. Hadoop入门 完全分布式运行模式-集群配置

    目录 集群配置 集群部署规划 配置文件说明 配置集群 群起集群 1 配置workers 2 启动集群 总结 3 集群基本测试 上传文件到集群 查看数据真实存储路径 下载 执行wordcount程序 配 ...

  4. 日常Java 2021/11/17

    应用程序转换成Applet 将图形化的Java应用程序(是指,使用AWT的应用程序和使用java程序启动器启动的程序)转换成嵌入在web页面里的applet是很简单的.下面是将应用程序转换成.Appl ...

  5. Web安全学习二

    目录 常见漏洞攻防 SQL注入 注入分类 按技巧分类 按获取数据的方式分类 注入检测 权限提升 数据库检测 绕过技巧 CheatSheet SQL Server Payload MySQL Paylo ...

  6. C++ 数组元素循环右移问题

    这道题要求不用另外的数组,并且尽量移动次数少. 算法思想:设计一个结构体存储数组数据和它应在的索引位置,再直接交换,但是这种方法不能一次性就移动完成,因此再加一个判断条件.等这个判断条件满足后就退出循 ...

  7. How is Quality Score Calculated?

    Google determines Quality Score slightly differently for each of the different advertising networks ...

  8. iOS 客户端获取七牛上传token

    一.官方参考文档: 1.上传策略http://developer.qiniu.com/article/developer/security/put-policy.html 2.上传凭证(即uptoke ...

  9. javaIO——输入输出流

    字节流与字符流 File类不支持对文件内容进行相关的操作,所有若要处理文件的内容,则需要通过流操作模式来完成. 流的基本操作步骤: Step1:根据文件路径创建File类对象. Step2:根据字节流 ...

  10. jdk1.6,1.7,1.8解压版无需安装(64位)

    1.java SE 1.6各个版本 jdk http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads ...