import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()) { long a = scanner.nextLong(); long b = scanner.nextLong(); long res1 = 0, res2 = 0, min = Long.MAX_VALUE; for (long i = a; i <= Math.sqrt(a * b); i++) { if ((a * b) % i == 0) { long temp = (a * b) / i; long p = gcd(i, temp); if (p == a) { if (min > i + temp) { min = i + temp; res1 = i; res2 = temp; } } } } System.out.println(res1 + " " + res2); } } public static long gcd(long a, long b){ if(a%b == 0)return b; return gcd(b, a%b); } } |
Double click to view unformatted code.