ZSTUOJ 4270: 同源数
来源:互联网 发布:淘宝代充平台 编辑:程序博客网 时间:2024/05/23 05:06
4270: 同源数
Time Limit: 3 Sec Memory Limit: 128 MB
Submit: 1356 Solved: 249
Description
如果x和y的质因子集合完全相同,那么我们就说他们是同源的。
比如说18 = 2 * 32,12 = 3 * 22;
Input
本题有多组数据(组数 <= 555555)。
每组数据输入形如:
x y
x, y为整数(1 <= x, y <= 1e18)
Output
输出形入:
ans
如果x, y为同源数,那么ans为”Yes”, 不然为”No”.
Sample Input
18 12
2 3
Sample Output
Yes
No
题目链接:http://oj.acm.zstu.edu.cn/JudgeOnline/problem.php?id=4270
题解:
令k=gcd(x, y),让x不断除以k且不断计算k==1?,如果k==1且a==1时,表明x和y的质因子相同,是同源数,否则输出No。
#include<stdio.h>#include<stdlib.h>#include<math.h>#include<algorithm>#include<string.h>#include<string>#include<stack>#include<queue>#include<set>#include<sstream>#include<iostream>#define INF 0x3f3f3f3fusing namespace std;typedef long long ll;ll gcd(ll a, ll b){ return b == 0 ? a:gcd(b, a%b);}bool fun(ll a, ll b){ ll k = gcd(a, b); while(1){ if(k == 1){ if(a == 1) return true; else return false; } a /= k; k = gcd(a, b); } return false;}int main(){ ll x, y; while(scanf("%lld%lld", &x, &y) == 2){ if(fun(x, y)) printf("Yes\n"); else printf("No\n"); } }
0 0
- zstuoj 4270: 同源数
- ZSTUOJ 4270: 同源数
- ZSTUoj 4270: 同源数 ( GCD
- zstu-4270同源数
- ZSTU4270 同源数
- Problem E: 同源数
- zstuoj 4357 数状数组维护前缀后缀最值、
- zstuoj 4355
- 2017浙理工校赛重现-E.同源数(gcd)
- String Game【ZSTUOJ--4212】
- Jug Hard【ZSTUOJ--4216】
- ZSTUOJ 4215 Landlocked
- ZSTUOJ 4212 String Game
- zstuoj 4243 牛吃草
- zstuoj 4246 萌新吃果果
- zstuoj 4243 牛吃草
- zstuoj 4274 约素
- zstuoj 4269 买iphone
- git常用命令以及使用技巧
- html5与安卓native交互,相互调用
- 【算法】牛客网模拟题编程部分3.23日
- UVA
- JAVA多线程之——线程的实现方式
- ZSTUOJ 4270: 同源数
- 在mac系统安装Apache Tomcat的详细步骤
- [leetcode]83. Remove Duplicates from Sorted List
- Jsp中标签使用:tag 文件方式 和 tld文件方式
- javaScript采用面向对象的方式实现实现拖拽
- jq-$.extend方法使用说明
- JAD-CACHE缓存框架1.0.2版本发布
- UWP入门(十二)--数据绑定用法
- JavaScript函数三种定义形式