View Code of Problem 3836

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            long x = in.nextLong();
            long y = in.nextLong();
            long multiply = x * y;
            long s = (long) Math.sqrt(multiply);
            long min = Long.MAX_VALUE;
            long a = 0;
            long b = 0;
            for (long i = x; i <= s; i++) {
                if ((multiply % i == 0) && yinshu(i, multiply / i) == x) {
                    long p = i + multiply / i;
                    if (min > p) {
                        min = p;
                        b = multiply / i;
                        a = i;
                    }
                }
            }
            System.out.println(a + " " + b);
        }
    }

    public static long yinshu(long a, long b) {
        long c = a % b;
        while (c != 0) {
            a = b;
            b = c;
            c = a % b;
        }
        return b;
    }
}

Double click to view unformatted code.


Back to problem 3836