結果

問題 No.442 和と積
ユーザー samplelpmassamplelpmas
提出日時 2017-04-14 20:02:47
言語 Java21
(openjdk 21)
結果
AC  
実行時間 121 ms / 1,000 ms
コード長 841 bytes
コンパイル時間 4,512 ms
コンパイル使用メモリ 71,568 KB
実行使用メモリ 56,140 KB
最終ジャッジ日時 2023-09-18 06:51:08
合計ジャッジ時間 5,542 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,284 KB
testcase_01 AC 117 ms
56,140 KB
testcase_02 AC 120 ms
55,696 KB
testcase_03 AC 120 ms
55,592 KB
testcase_04 AC 120 ms
55,772 KB
testcase_05 AC 117 ms
55,956 KB
testcase_06 AC 118 ms
55,588 KB
testcase_07 AC 119 ms
55,604 KB
testcase_08 AC 119 ms
55,844 KB
testcase_09 AC 119 ms
55,748 KB
testcase_10 AC 119 ms
56,056 KB
testcase_11 AC 119 ms
55,720 KB
testcase_12 AC 119 ms
55,656 KB
testcase_13 AC 119 ms
55,668 KB
testcase_14 AC 120 ms
55,724 KB
testcase_15 AC 118 ms
55,628 KB
testcase_16 AC 120 ms
55,496 KB
testcase_17 AC 119 ms
55,612 KB
testcase_18 AC 121 ms
55,904 KB
testcase_19 AC 120 ms
55,744 KB
testcase_20 AC 120 ms
55,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.BigInteger;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        BigInteger A = new BigInteger(sc.next());
        BigInteger B = new BigInteger(sc.next());

        BigInteger sum = A.add(B);
        BigInteger product = A.multiply(B);

        BigInteger bigger;
        BigInteger smaller;

        if (sum.compareTo(product) < 0) {
            bigger = product;
            smaller = sum;
        } else {
            bigger = sum;
            smaller = product;
        }

        while (bigger.compareTo(BigInteger.ZERO) != 0) {

            BigInteger tmp = bigger;
            bigger = smaller.mod(tmp);
            smaller = tmp;

        }

        BigInteger gcd = smaller;

        System.out.println(gcd);

    }

}
0