hdu 5175(数论)
Misaki's Kiss again
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1621 Accepted Submission(s): 414
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
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
5
15
1
2
Case #2:
1
4
Case #3:
3
10 12 14
In the third sample, gcd(15,10)=5 and (15 xor 10)=5, gcd(15,12)=3 and (15 xor 12)=3,gcd(15,14)=1 and (15 xor 14)=1
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long LL;
LL factor[];
LL gcd(LL a,LL b){
return b==?a:gcd(b,a%b);
}
LL ans[];
int main()
{
LL n;
int t=;
while(scanf("%lld",&n)!=EOF){
factor[] = ;
int id = ;
for(LL i=;i*i<=n;i++){
if(n%i==){
if(i*i==n){
factor[id++] = i;
}else{
factor[id++] = i;
factor[id++] = n/i;
}
}
}
factor[id++] = n;
int cnt = ;
for(LL i=;i<id;i++){
LL M = n^factor[i];
if(M<||M>n) continue;
if(gcd(n,M)==factor[i]){
ans[cnt++] = M;
}
}
printf("Case #%d:\n",t++);
if(cnt==){
printf("0\n\n");
}else{
sort(ans,ans+cnt);
printf("%d\n",cnt);
for(int i=;i<cnt-;i++){
printf("%lld ",ans[i]);
}
printf("%lld\n",ans[cnt-]);
}
}
return ;
}
hdu 5175(数论)的更多相关文章
- GCD and LCM HDU 4497 数论
GCD and LCM HDU 4497 数论 题意 给你三个数x,y,z的最大公约数G和最小公倍数L,问你三个数字一共有几种可能.注意123和321算两种情况. 解题思路 L代表LCM,G代表GCD ...
- HDU 4497 数论+组合数学
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4497 解题思路:将满足条件的一组x,z,y都除以G,得到x‘,y',z',满足条件gcd(x',y' ...
- hdu 4542 数论 + 约数个数相关 腾讯编程马拉松复赛
题目:http://acm.hdu.edu.cn/showproblem.php?pid=4542 小明系列故事--未知剩余系 Time Limit: 500/200 MS (Java/Others) ...
- hdu 4961 数论?
http://acm.hdu.edu.cn/showproblem.php?pid=4961 给定ai数组; 构造bi, k=max(j | 0<j<i,a j%ai=0), bi=ak; ...
- hdu 1664(数论+同余搜索+记录路径)
Different Digits Time Limit: 10000/4000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- hdu 3641 数论 二分求符合条件的最小值数学杂题
http://acm.hdu.edu.cn/showproblem.php?pid=3641 学到: 1.二分求符合条件的最小值 /*================================= ...
- hdu 4059 数论+高次方求和+容斥原理
http://acm.hdu.edu.cn/showproblem.php? pid=4059 现场赛中通过率挺高的一道题 可是容斥原理不怎么会.. 參考了http://blog.csdn.net/a ...
- HDU 4651 数论 partition 求自然数的拆分数
别人的解题报告: http://blog.csdn.net/zstu_zlj/article/details/9796087 我的代码: #include <cstdio> #define ...
- hdu 5505(数论-gcd的应用)
GT and numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
随机推荐
- 用vs调试项目页面无样式
ASP.NET Development Server 上的文件授权 在文件系统网站中,静态文件(例如图像和样式表)遵守 ASP.NET 授权.例如,如果禁用了对静态文件的匿名访问,匿名用户则不能使用文 ...
- Hibernate常用方法之_插入
1.使用session的save方法进行插入 public void saveUser(User user){ Session session = null; Transaction transact ...
- DPDK 分析
DPDK 分析 来源 https://www.cnblogs.com/bakari/p/8404650.html 高性能网络技术 随着云计算产业的异军突起,网络技术的不断创新,越来越多的网络设备基础架 ...
- 黑群晖DSM 6.1网卡支持列表
黑群晖DSM 6.1网卡支持列表 Network Drivers====================================AMDamd8111e : AMD 8111 (new PCI ...
- 【TMD模拟赛】上低音号 链表
这道题一看有两个出发现点,一枚举点去找边界,想了一会就Pass了...,二是枚举相框,我们最起码枚举两个边界,然后发现平行边界更好处理,然而仍然只有30分,这个时候就来到了链表的神奇应用,我们枚举上界 ...
- [zhuan]Android安全讲座第九层(二) 内存dump
http://sunzeduo.blog.51cto.com/2758509/1409450 近来android上越来越多的应用对自身的保护机制加强了重视,主要表现在几个方面. 1 dex加壳 2 s ...
- codeforces 1015E1&&E2
E1. Stars Drawing (Easy Edition) time limit per test 3 seconds memory limit per test 256 megabytes i ...
- Join to domain powershell script
Join to domain powershell script $username = "domain\admin" $Password = "xxxxxxxx&quo ...
- Python基础(9)三元表达式、列表解析、生成器表达式
一.三元表达式 三元运算,是对简单的条件语句的缩写. # if条件语句 if x > f: print(x) else: print(y) # 条件成立左边,不成立右边 x if x > ...
- 将setter方法与itemClick: 进行类比
https://www.evernote.com/shard/s227/sh/a0c3afa3-8792-4756-8594-d2387a7f57ad/b561ff665af9ad401c8e ...