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 ...
随机推荐
- Jquery 跨域请求JSON数据问题
制作网站时,我们有时候为了方便快捷会调用别人写好的API接口,或者是调用一些免费的API接口获得JSON数据.比如天气,农历,网站备案信息查询等. 但是,这些API接口都是别人自己服务器上的,我们要调 ...
- 在虚拟机安装 Linux 系统(菜鸡级别)
处理器数量看个人 剩下按照推荐的配置选择就OK 启动客户端 -> Enter进入 /为其它盘./Boot为根目录 可不勾选
- express框架 中间件
- 【bzoj2957】楼房重建 分块+二分查找
题目描述 小A的楼房外有一大片施工工地,工地上有N栋待建的楼房.每天,这片工地上的房子拆了又建.建了又拆.他经常无聊地看着窗外发呆,数自己能够看到多少栋房子.为了简化问题,我们考虑这些事件发生在一个二 ...
- ScrollBarsEnabled的使用
在WinForm中通过WebBrowser获取网页,我想把WebBrowser的ScollBar去掉,我的网页不需要滚动条. 设置方法如下:单击WebBrowser设计页面,在属性页面有一个Scrol ...
- hdu 2838 Cow Sorting (树状数组)
Cow Sorting Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- cdh版本的zookeeper安装以及配置(伪分布式模式)
需要的软件包:zookeeper-3.4.5-cdh5.3.6.tar.gz 1.将软件包上传到Linux系统指定目录下: /opt/softwares/cdh 2.解压到指定的目录:/opt/mo ...
- VS查看DLL接口
应用程序Microsoft Visual Studio 2010的Visual Studio Tools文件夹中打开Visual Studio Command Prompt (2010)命令窗口 du ...
- BZOJ3533 [Sdoi2014]向量集 【线段树 + 凸包 + 三分】
题目链接 BZOJ3533 题解 我们设询问的向量为\((x_0,y_0)\),参与乘积的向量为\((x,y)\) 则有 \[ \begin{aligned} ans &= x_0x + y_ ...
- dns服务 很多问题,后续再研究
慕课网:http://www.imooc.com/video/5220 参考:http://jingyan.baidu.com/article/870c6fc32c028eb03fe4be30.htm ...