Misaki's Kiss again(hdu5175)
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
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
For each testcase, contains a integets N(0<N<=1010)
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
1
2
1
4
3
10 12 14
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)的更多相关文章
- hdu 5175 Misaki's Kiss again(GCD和异或)
题意: 给一个数N. 如果GCD(N,M) = N XOR M,则称M是一个kiss 1<=M<=N 问总共有多少个kiss.并且列出所有的值. 思路: 思路一:枚举M.有大量的GCD ...
- Form验证(转)
代码写 N 久了,总想写得别的.这不,上头说在整合两个项目,做成单一登录(Single Sign On),也有人称之为“单点登录”.查阅相关文档后,终于实现了,现在把它拿出来与大家一起分享.或许大家会 ...
- 跟我一起云计算(5)——Shards
什么是sharding Sharding的基本思想就要把一个数据库切分成多个部分放到不同的数据库 (server)上,从而缓解单一数据库的性能问题.不太严格的讲,对于海量数据的数据库,如果是因为表多而 ...
- Angular(1)
1.设计原则 1.YAGNI 不要把未来需求引入当前工程 2.KISS keep it simple and stupid 语义化标记 合理注释 符合规定的命名 3.DRY(don't re ...
- 你应当如何学习C++(以及编程)(转载)
你应当如何学习C++(以及编程)(rev#1) By 刘未鹏(pongba) C++的罗浮宫(http://blog.csdn.net/pongba) Javascript是世界上最受误解的语言,其实 ...
- 【转】理解依赖注入(IOC)和学习Unity
IOC:英文全称:Inversion of Control,中文名称:控制反转,它还有个名字叫依赖注入(Dependency Injection).作用:将各层的对象以松耦合的方式组织在一起,解耦,各 ...
- 理解依赖注入(IOC)和学习Unity
资料1: IOC:英文全称:Inversion of Control,中文名称:控制反转,它还有个名字叫依赖注入(Dependency Injection). 作用:将各层的对象以松耦合的方式组织在一 ...
- [欢度国庆]为什么我们今天还要学习和使用C++?(转载)
在各种新的开发语言层出不穷的今天,在Java和C#大行其道今天,我们为什么还要学习和使用C++?现在学习C++将来有用吗?学习C++要花费那么多时间和精力,这一切都值得吗?现在学习C++有钱途吗? 这 ...
- 对面向对象程序设计(OOP)的认识
前言 本文主要介绍面向对象(OO)程序设计,以维基百科的解释: 面向对象程序设计(英语:Object-oriented programming,缩写:OOP),指一种程序设计范型,同时也是一种程序开发 ...
随机推荐
- EPOLL原理详解(图文并茂)
文章核心思想是: 要清晰明白EPOLL为什么性能好. 本文会从网卡接收数据的流程讲起,串联起CPU中断.操作系统进程调度等知识:再一步步分析阻塞接收数据.select到epoll的进化过程:最后探究e ...
- Python查找最长回文暴力方法
查找最长回文子串 给定一个字符串 s,找到 s 中最长的回文子串.你可以假设 s 的最大长度为1000. 例如1: 输入: "babad" 输出: "bab" ...
- ansible-playbook 安装redis 主从
ansible-playbook 安装redis 主从 手动在测试机上安装一遍redis,最好使用utils下面的install_server.sh安装服务,然后将redis的配置文件和init需要的 ...
- C++之error: cannot bind non-const lvalue reference of type ‘myString&’ to an rvalue of type ‘myString’
先看代码(不想看代码可以直接看代码后的问题描述) //header.h #ifndef _HEADER_H #define _HEADER_H #define defaultSize 128 #inc ...
- 11-如何通过newman生成不同类型的测试报告
postman生成测试报告需要一个插件:newman ,并且这个插件需要先安装 . 安装步骤: 安装nodejs: newman是由nodejs开发,所以要先安装它的运行环境,下载地址:http:// ...
- Linux学习 - 系统定时任务
1 crond服务管理与访问控制 只有打开crond服务打开才能进行系统定时任务 service crond restart chkconfig crond on 2 定时任务编辑 crontab [ ...
- OpenStack之三: 安装MySQL,rabbitmq, memcached
官网地址:https://docs.openstack.org/install-guide/environment-sql-database-rdo.html #:安装mysql [root@mysq ...
- 监控Linux服务器网站状态的SHELL脚本
1,监控httpd状态码的shell脚本代码. #!/bin/sh #site: www.jquerycn.cn # website[0]=www.jquerycn.cn/chuzu/' #网站1 m ...
- String.split()与StringUtils.split()的区别
import com.sun.deploy.util.StringUtils; String s =",1,,2,3,4,,"; String[] split1 = s.split ...
- Mockito 简介
Mockito 是一种 Java Mock 框架,主要是用来做 Mock 测试,它可以模拟任何 Spring 管理的 Bean.模拟方法的返回值.模拟抛出异常等等,在了解 Mockito 的具体用法之 ...