View Code of Problem 59

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String input = sc.nextLine();
        String[] nums = input.split(" ");
        int a = Integer.parseInt(nums[0]);
        int b = Integer.parseInt(nums[1]);
        int x, y = 0;

        for(int i = Math.min(a, b); i >= 1; i --) {
            if(a % i == 0 && b % i == 0) {
                y = i;
                break;
            }
        }

        x = a * b / y;
        System.out.println(x + " " + y);
    }
}

Double click to view unformatted code.


Back to problem 59