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. typora 图床配置方法

    学习计算机的同学,在日常学习中难免会记笔记,写文档.相信大家记笔记大部分使用的都是 Markdown 吧,如果到现在还没接触,那我强烈建议你去学习一下,大概几分钟就可以搞定它. 注:下文用到的所有软件 ...

  2. 点击下拉选择触发事件【c#】

    <asp:DropDownList ID="ddlRegionList" runat="server" AutoPostBack="true&q ...

  3. Express中间件原理详解

    前言 Express和Koa是目前最主流的基于node的web开发框架,他们的开发者是同一班人马.貌似现在Koa更加流行,但是仍然有大量的项目在使用Express,所以我想通过这篇文章说说Expres ...

  4. Android消除Toast延迟显示

    Toast可以用来显示音量改变或者保存更新消息,如果用户一直点击,Toast会排队一个一个的,直到消息队列全部显示完,这样的效果显然是不好的,下面来看解决方法    Toast.makeText(ac ...

  5. When does compiler create default and copy constructors in C++?

    In C++, compiler creates a default constructor if we don't define our own constructor (See this). Co ...

  6. Type of 'this' pointer in C++

    In C++, this pointer is passed as a hidden argument to all non-static member function calls. The typ ...

  7. vue 中使用import导入 script 在线链接

    一般我们在vue中导入另外一个文件或者文件中的方法,我们都是使用import来实现他的,那么问题来了,现在我们要导入的不是另外的一个文件,而是在线链接,这该怎么办?我们也使用了 import * as ...

  8. sqlserver 删除表分区

    我们都知道,SQL server2008R2企业版以及一些其它的版本支持分区函数,当你在这些数据库备份后想在一些不支持分区函数的数据库做还原时,就会失败. 下面我们来解决这个问题. 1.备份数据库!备 ...

  9. mysq中char,varchar,text的区别

    mysql5.0.3以后,n都表示字符数(varchar(n)) 检索效率 char > varchar > text 当varchar长度超过255之后,跟text一致,但是设置varc ...

  10. jstl中的foreach标签

    <%@ page import="java.util.ArrayList" %><%@ page import="java.util.List" ...