#include <iostream> #include <string> #include <cmath> #include <algorithm> #include <stack> #include <vector> #include <set> #include <queue> using namespace std; int gcd(int a, int b) { return b==0?a:gcd(b, a%b); } int lcm(int a, int b) { return a * b / gcd(a, b); } int main() { int i, j, flag, k; long long n, m, t; int x, y; while (cin >> x >> y) { int min = 0xffffff; int x0 = 0; int y0 = 0; for (i = x; i <= sqrt(x*y);) { j = x * y / i; //cout << i << " " << j << endl; if (gcd(i, j) == x &&lcm(i,j)==y&& i + j < min) { x0 = i; y0 = j; } i += x; } cout << x0 << " " << y0 << endl; } return 0; } |
Double click to view unformatted code.