結果

問題 No.442 和と積
ユーザー Daigo HIROOKADaigo HIROOKA
提出日時 2018-06-13 01:39:44
言語 Java21
(openjdk 21)
結果
AC  
実行時間 123 ms / 1,000 ms
コード長 545 bytes
コンパイル時間 2,899 ms
コンパイル使用メモリ 71,944 KB
実行使用メモリ 56,380 KB
最終ジャッジ日時 2023-09-18 07:02:18
合計ジャッジ時間 6,355 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
55,740 KB
testcase_01 AC 118 ms
55,892 KB
testcase_02 AC 117 ms
55,724 KB
testcase_03 AC 120 ms
55,748 KB
testcase_04 AC 119 ms
53,844 KB
testcase_05 AC 117 ms
56,072 KB
testcase_06 AC 121 ms
55,840 KB
testcase_07 AC 120 ms
53,468 KB
testcase_08 AC 119 ms
55,456 KB
testcase_09 AC 118 ms
56,112 KB
testcase_10 AC 120 ms
56,068 KB
testcase_11 AC 117 ms
55,840 KB
testcase_12 AC 120 ms
55,976 KB
testcase_13 AC 120 ms
56,112 KB
testcase_14 AC 118 ms
56,380 KB
testcase_15 AC 120 ms
55,976 KB
testcase_16 AC 120 ms
55,760 KB
testcase_17 AC 123 ms
55,864 KB
testcase_18 AC 119 ms
56,316 KB
testcase_19 AC 120 ms
56,056 KB
testcase_20 AC 119 ms
56,072 KB
権限があれば一括ダウンロードができます

ソースコード

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