GCD & LCM Inverse
Time Limit: 2000MS |
|
Memory Limit: 65536K |
Total Submissions: 18825 |
|
Accepted: 3486 |
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
算法分析:
题意:
给出gcd(a,b)和lcm(a,b),求a和b,如果存在多组方案则输出a+b最小的那一组
分析:
首先,我们可以看出(x/gcd)*(y/gcd)=lcm/gcd,并且x/gcd和y/gcd互质,那么我们先利用把所有的质数求出来Pollard_Rho,将相同的质数合并,现在的问题转变成把合并后的质数分为两堆,使得x+y最小,然后我们可以采用二进制枚举(解释点这里),一个个枚举出来。
代码实现:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include