View Code of Problem 59


import java.util.Scanner;

public class Main {
    public static int gongyinshu(int a,int b){
        if(b%a == 0){
            return a;
        }
        int res = 1;
        for(int i = 2;i<a;i++){
            if(a%i == 0 && b%i == 0){
                res = i;
            }
        }
        return res;
    }
    public static int gongbeishu(int a,int b){
        if(b%a == 0){
            return b;
        }
        for(int i = b*2;i<=a*b;i+=b){
            if(i%a == 0){
                return i;
            }
        }
        return a*b;
    }
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();//xiao
        int b = scanner.nextInt();//da
        if(a>b){
            int t = a;
            a = b;
            b = t;
        }

        System.out.print(gongbeishu(a,b)+" "+gongyinshu(a,b));
    }
}

Double click to view unformatted code.


Back to problem 59