UVA
来源:互联网 发布:淘宝文案格式模板 编辑:程序博客网 时间:2024/06/17 02:32
讲道理,学 c 语言的时候肯定学过 求 GCD 和 LCM,
一般是求出 a, b 的GCD后, LCM = a * b / GCD ;
这样就ok了, (LCM / GCD) = ( a / GCD ) * ( b / GCD );
而且 ( a / GCD ) 和 ( b / GCD ) 互质
** 额,,我在输入 G 和 L 是忘记判断合法性,错了,也就是 样例2,,,2333
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<set>#include<stack>#include<queue>#include<algorithm>// cout << " === " << endl;using namespace std;typedef long long ll;const int maxn = 1000000 + 7, INF = 0x3f3f3f3f, mod = 1e9+7;int T;ll G, L;ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a%b);}int main () { scanf("%d", &T); while(T--) { scanf("%lld%lld", &G, &L); if( (L/G) * G != L) { cout << -1 << endl; continue; } else L /= G; int f = 0; for(ll i = 1; i * i <= L; ++i) { ll t = L / i; if(i*t == L && gcd(i, t) == 1 ) { f = 1; cout << i*G << " " << t*G << endl; break; } } if(!f) cout << -1 << endl; } return 0;}
阅读全文
2 0
- uva
- UVA
- UVA
- UVA
- uva
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- centos7下安装mysql,网上文章都不太准
- Object-c 快速入门
- npoi table样板填写并导出word
- observable
- Elasticsearch-2.3.x填坑之路
- UVA
- c# base关键字的用法
- mysql数据表索引的使用
- 误用关键字-_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax;
- Java基础——泛型与集合
- docker镜像安装java-openjdk以及openjdk-debuginfo
- postman的使用方法详解!最全面的教程
- 为什么常规HashMap不是线程安全的?
- Swift3.0——Swift中下划线的妙用,_的用法