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. 55. Binary Tree Preorder Traversal

    Binary Tree Preorder Traversal My Submissions QuestionEditorial Solution Total Accepted: 119655 Tota ...

  2. 10.Power of Two-Leetcode

    Given an integer, write a function to determine if it is a power of two. class Solution { public: bo ...

  3. JAVA写入TXT

    用java生成txt文件有两种方式: 1)是通过字符流(或字节流): 2)是直接调用PrintWriter类. 具体实现过程如下: 1)字符流(字节流) 代码如下: import java.io.Fi ...

  4. nuxt.js相关随笔

    对于nuxt.js从未接触,对于项目需要进行零散了解,作此归纳,以下都是一个新手的拙见与理解,有不同意见欢迎提出,但请勿喷. 一.项目创建 npx create-nuxt-app projectNam ...

  5. HTML5 之 FileReader 的使用 (二) (网页上图片拖拽并且预显示可在这里学到) [转载]

    转载至 : http://www.360doc.com/content/14/0214/18/1457948_352511645.shtml FileReader 资料(英文): https://de ...

  6. 如果通过 IP 判断是否是爬虫

    通过 IP 判断爬虫 如果你查看服务器日志,看到密密麻麻的 IP 地址,你一眼可以看出来那些 IP 是爬虫,那些 IP 是正常的爬虫,就像这样: 在这密密麻麻的日志里面,我们不仅要分辨出真正的爬虫 I ...

  7. [转]C++中const的使用

    原文链接:http://www.cnblogs.com/xudong-bupt/p/3509567.html 平时在写C++代码的时候不怎么注重const的使用,长久以来就把const的用法忘记了 写 ...

  8. python web框架学习笔记

    一.web框架本质 1.基于socket,自己处理请求 #!/usr/bin/env python3 #coding:utf8 import socket def handle_request(cli ...

  9. 【Service】【Database】【MySQL】基础

    1. 概念 1.1. 作者:Unireg 1.2. MySQL AB --> MySQL Solaris:二进制版本: 1.3. 官方网站: MySQL: www.mysql.com Maria ...

  10. 【Java基础】Java反射——Private Fields and Methods

    Despite the common belief it is actually possible to access private fields and methods of other clas ...