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 ...
随机推荐
- 最快的Hash表算法
我们由一个简单的问题逐步入手:有一个庞大的字符串数组,然后给你一个单独的字符串,让你从这个数组中查找是否有这个字符串并找到它,你会怎么做?有一个方法最简单,老老实实从头查到尾,一个一个比较,直到找到为 ...
- MD5消息摘要算法
Message Digest 5(消息摘要算法)为计算机安全领域广泛使用的一种散列函数,用以提供消息的完整性保护. MD5的作用是让大容量信息在用数字签名软件签署私人密钥前被"压缩" ...
- 【bzoj3940】[Usaco2015 Feb]Censoring AC自动机
题目描述 Farmer John has purchased a subscription to Good Hooveskeeping magazine for his cows, so they h ...
- BZOJ4327 JSOI2012玄武密码(AC自动机)
当然可以在SA上二分答案,但看起来会被卡log.考虑对模板串建出AC自动机,用母串在上面跑,标记上所有能到达的点.注意到达某个点时需要标记所有其通过fail指针可以走到的点,如果遇到一个标记过的点就可 ...
- codeforces803D. Magazine Ad
D. Magazine Adtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutput ...
- jwplayer 部署方案1
<body> <div id="my_player" data_src="http://xx.com/jwplayer/uploads/test.mp4 ...
- php-instanceof运算符
1.关于 instanceof 的一些基本概念 1).instanceof 用于确定一个PHP变量是否属于某一类class的实例: <?php class MyClass { } class N ...
- 模拟实现jdk动态代理
实现步骤 1.生成代理类的源代码 2.将源代码保存到磁盘 3.使用JavaCompiler编译源代码生成.class字节码文件 4.使用JavaCompiler编译源代码生成.class字节码文件 5 ...
- 链接oracle数据库 生成表对应的javabean
package com.databi.utils; import java.io.File; import java.io.FileOutputStream; import java.io.IOExc ...
- IE9,IE10 CSS因Mime类型不匹配而被忽略问题 (转)
写页面的时候在chrome,fireforks等页面上显示正常,但是换成IE9,IE10之后就完全没有样式了,报错信息是CSS 因 Mime 类型不匹配而被忽略,下面与大家分享下这个问题的相关的回答 ...