hdu 5175 Misaki's Kiss again(GCD和异或)
题意:
给一个数N。
如果GCD(N,M) = N XOR M,则称M是一个kiss 1<=M<=N
问总共有多少个kiss。并且列出所有的值。
思路:
思路一:枚举M。有大量的GCD(N,M)值相等。但是N XOR M=X。当X是定值是,M一定只有一个。所以这个方法明显有大量重复。
发现知道GCD(N,M)的值,可直接求出M。搞定。
令gcd(n,m)=d,可知道d是n的约数
有d=(n xor m)=(m xor n),所以m=(d xor n)。
可发现gcd(n,(d xor n))=d。
*注意:gcd(a,b) 当a或b为零时,gcd(a,b)的值为1。这个要单独判断。
还有一个(d xor n)有可能大于n。这个也要单独判断。
代码:
ll N; ll gcd(ll a,ll b){
if(b==0) return a;
return gcd(b,a%b);
} int T = 0;
ll ans[100005];
int kissNum; int main(){ while(scanf("%I64d",&N)!=EOF){ kissNum = 0; for(ll i=1;i*i<=N;++i){
if(N%i==0){
ll x = N^i;
if(x>0 && x<=N && gcd(N,x)==i){
ans[++kissNum] = x;
}
ll t = N/i;
if(t!=i){
ll xx = N^t;
if(xx>0 && xx<=N && gcd(N,xx)==t){
ans[++kissNum] = xx;
}
}
}
} printf("Case #%d:\n%d\n",++T,kissNum);
if(kissNum>0){
sort(ans+1,ans+1+kissNum);
printf("%I64d",ans[1]);
rep(i,2,kissNum) printf(" %I64d",ans[i]);
}
cout<<endl;
} return 0;
}
hdu 5175 Misaki's Kiss again(GCD和异或)的更多相关文章
- hdu 5175 Misaki's Kiss again
Misaki's Kiss again Accepts: 75 Submissions: 593 Time Limit: 2000/1000 MS (Java/Others) Memory L ...
- hdu 5175(数论)
Misaki's Kiss again Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- Misaki's Kiss again(hdu5175)
Misaki's Kiss again Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- HDU 1222 Wolf and Rabbit(gcd)
HDU 1222 Wolf and Rabbit (最大公约数)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...
- HDU 1019 Least Common Multiple【gcd+lcm+水+多个数的lcm】
Least Common Multiple Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Ot ...
- 【HDU 5381】 The sum of gcd (子区间的xx和,离线)
[题目] The sum of gcd Problem Description You have an array A,the length of A is nLet f(l,r)=∑ri=l∑rj= ...
- hdu 4497(排列组合+LCM和GCD)
GCD and LCM Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total ...
- hdu 5974 A Simple Math Problem gcd(x,y)=gcd((x+y),lcm(x,y))
题目链接 题意 现有\[x+y=a\\lcm(x,y)=b\]找出满足条件的正整数\(x,y\). \(a\leq 2e5,b\leq 1e9,数据组数12W\). 思路 结论 \(gcd(x,y)= ...
- HDU - 5584 LCM Walk (数论 GCD)
A frog has just learned some number theory, and can't wait to show his ability to his girlfriend. No ...
随机推荐
- 基于pgpool搭建postgressql集群部署
postgresql集群搭建 基于pgpool中间件实现postgresql一主多从集群部署,这里用两台服务器作一主一从示例 虚拟机名 IP 主从划分 THApps 192.168.1.31 主节点 ...
- Spring Cloud Hystrix 学习(三)请求合并
什么是请求合并?我们先来看两张图: 上方的两张图中,第二张可以看出服务端只执行了一次响应,这就是请求合并.客户端新增的请求合并模块,内部存在一个等待的时间窗口,将一定时间段内满足条件的请求进行合并,以 ...
- 4.深入TiDB:执行计划执行过程详解
本文基于 TiDB release-5.1进行分析,需要用到 Go 1.16以后的版本 转载请声明出处哦~,本篇文章发布于luozhiyun的博客:https://www.luozhiyun.com/ ...
- three.js 元素跟随物体效果
需求: 1.实现元素跟随指定物体位置进行位置变化 实现方案: 1--- Sprite 精灵 2 --- cavans 画图后创建模型贴图 3 --- CSS2DRenderer渲染方式 4 --- ...
- Qt中的ui文件转换为py文件
将pyuic5 -o demo.py demo.ui写入ui-py.bat文件(自定义文件),将ui文件与ui-py.bat文件放在同一文件夹,双击.bat文件即可生成.py文件
- Social Networ
http://hansheng.xiong99.com.cn/ Paper:Dynamic Networks in Large Financial and Economic Systems
- 前端快闪三:多环境灵活配置react
你已经使用Create React App脚手架搭建了React应用,现在该部署了. 一般会使用npm run build或者yarn build构建出静态资源, 由web服务器承载. 您会体验到 多 ...
- 【原创】SystemVerilog中的typedef前置声明方式
SystemVerilog中,为了是代码简洁.易记,允许用户根据个人需要使用typedef自定义数据类型名,常用的使用方法可参见"define和typedef区别".但是在Syst ...
- 查看显卡报错:NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running.
当输入nvidia-smi时出现 NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. Make ...
- mysql8.0.20下载安装教程
mysql8.0.20安装教程 1.浏览器搜索mysql下载安装 地址:https://dev.mysql.com/downloads/mysql/ 2.登录或者不登录下载 3.下载的是一个压缩包,直 ...