POJ5429 GCD & LCM Inverse
来源:互联网 发布:优步司机登录网络错误 编辑:程序博客网 时间:2024/05/22 11:38
GCD & LCM Inverse
Time Limit: 2000MS Memory Limit: 65536KTotal Submissions: 9913 Accepted: 1841
Description
Given two positive integers a and b, we can easily calculate the greatest common divisor (GCD) and the least common multiple (LCM) of a and b. But what about the inverse? That is: given GCD and LCM, finding a and b.
Input
The input contains multiple test cases, each of which contains two positive integers, the GCD and the LCM. You can assume that these two numbers are both less than 2^63.
Output
For each test case, output a and b in ascending order. If there are multiple solutions, output the pair with smallest a + b.
Sample Input
3 60
Sample Output
12 15
Source
POJ Achilles
算是钻空子解法了。。算法没变,C++ TLE,java ac..
import java.util.Scanner;public class Main {static long gcd(long a, long b) {long c;while(b != 0) {c = a % b;a = b;b = c;}return a;}public static void main(String[] args) {Scanner cin = new Scanner(System.in);long a, b, c, i;while(cin.hasNext()) {a = cin.nextLong();b = cin.nextLong();c = b / a;for(i = (long)Math.sqrt(c); i > 0; --i)if(c % i == 0 && gcd(i, c / i) == 1) {System.out.println(i*a + " " + c/i*a);break;}}}}
0 0
- POJ5429 GCD & LCM Inverse
- GCD & LCM Inverse
- POJ2429 GCD & LCM Inverse
- GCD & LCM Inverse POJ
- GCD & LCM Inverse POJ
- poj 2429 GCD & LCM Inverse
- poj 2429 GCD & LCM Inverse
- Hoj 2010 GCD & LCM Inverse
- poj 2429 GCD & LCM Inverse
- POJ 2429 GCD & LCM Inverse
- poj 2429 GCD & LCM Inverse
- POJ-2429 GCD & LCM Inverse
- Poj2429 inverse of LCM&GCD
- GCD & LCM Inverse(目前超时)
- Hoj 2010 GCD & LCM Inverse
- poj 2429 GCD & LCM Inverse
- [数论]HOJ 2010 GCD & LCM Inverse
- POJ 2429 GCD & LCM Inverse 因式分解
- 静静的下午
- Java中ClassPath设置
- Oracle ADF 开发必读
- RelativeLayout
- 6.1 我所知的全部数学内容
- POJ5429 GCD & LCM Inverse
- 基于Oracle ADF的应用程序开发
- STM32串口中断接收方式详细比较
- eclipse+cloudsim 第一天
- 敌兵布阵
- poj 2139 Six Degrees of Cowvin Bacon floyd算法
- HDU—— 1005 Number Sequence
- 《人月神话》阅读笔记
- I Hate It