結果

問題 No.442 和と積
ユーザー aaaaasatoriaaaaasatori
提出日時 2018-02-16 14:57:00
言語 Java21
(openjdk 21)
結果
AC  
実行時間 125 ms / 1,000 ms
コード長 554 bytes
コンパイル時間 3,093 ms
コンパイル使用メモリ 72,392 KB
実行使用メモリ 56,304 KB
最終ジャッジ日時 2023-09-18 06:59:25
合計ジャッジ時間 6,679 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,956 KB
testcase_01 AC 122 ms
55,700 KB
testcase_02 AC 123 ms
55,776 KB
testcase_03 AC 125 ms
55,860 KB
testcase_04 AC 124 ms
55,856 KB
testcase_05 AC 123 ms
55,960 KB
testcase_06 AC 124 ms
56,008 KB
testcase_07 AC 125 ms
55,856 KB
testcase_08 AC 125 ms
55,764 KB
testcase_09 AC 125 ms
55,860 KB
testcase_10 AC 124 ms
56,184 KB
testcase_11 AC 124 ms
55,704 KB
testcase_12 AC 125 ms
55,840 KB
testcase_13 AC 125 ms
55,696 KB
testcase_14 AC 125 ms
55,912 KB
testcase_15 AC 122 ms
55,888 KB
testcase_16 AC 123 ms
55,724 KB
testcase_17 AC 121 ms
55,916 KB
testcase_18 AC 122 ms
56,304 KB
testcase_19 AC 123 ms
56,076 KB
testcase_20 AC 124 ms
55,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class No442 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		if(b > a) {
			long x = b;
			b = a;
			a = x;
		}
		long r;
		long g;
		long gcd;
		long A = a;
		long B = b;
		
		while(true) {
			if(A % B == 0) {
				break;
			}
			r = A % B;
			A = B;
			B = r;
		}
		g = B; // g=gcd(A,B)
		A = a/g + b/g;
		while(true) {
			if(A % B == 0) {
				break;
			}
			r = A % B;
			A = B;
			B = r;
		}
		
		System.out.println(B * g);
	}
}
0