結果

問題 No.442 和と積
ユーザー Daigo HIROOKA
提出日時 2018-06-13 01:39:44
言語 Java
(openjdk 23)
結果
AC  
実行時間 127 ms / 1,000 ms
コード長 545 bytes
コンパイル時間 3,196 ms
コンパイル使用メモリ 74,788 KB
実行使用メモリ 41,404 KB
最終ジャッジ日時 2024-07-04 23:13:35
合計ジャッジ時間 6,507 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

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

		long a = sc.nextLong();
		long b = sc.nextLong();

		// gcd(A+B, A*B);
		// = g*gcd(a+b, a*b*g); // g = gcd(A, B), a = A/g, b = B/g;
		// = g*gcd(a+b, g); // a, b are disjoint, so a+b, a*b are also disjoint
		long g = gcd(a, b);
		long gd = gcd((a+b)/g, g);
		
		System.out.println(g*gd);
	}
	private static long gcd(long x, long y){
		long tmp;
		while((tmp = x%y) != 0){
			x = y;
			y = tmp;
		}
		return y;
	}
}
0