publicstaticvoidmain(String[] args)throws Exception { BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String str = in.readLine(); String[] split = str.split(" "); int a = Integer.parseInt(split[0]); int b = Integer.parseInt(split[1]); int gcd = gcd(a, b); out.write(gcd + "\n"); out.write(lcm(a, b, gcd) + "\n"); out.flush(); out.close(); ; in.close(); ; }
publicstaticintgcd(int a, int b){ while (b != 0) { int r = a % b; a = b; b = r; } return a; } //재귀를 이용한 gcd publicstaticlonggcd2(long a, long b){ return b != 0 ? gcd(b, a % b) : a; }
publicstaticintlcm(int a, int b, int gcd){ return (a * b) / gcd; } }