結果

問題 No.442 和と積
ユーザー jp_stejp_ste
提出日時 2016-11-11 23:43:43
言語 Java21
(openjdk 21)
結果
AC  
実行時間 123 ms / 1,000 ms
コード長 774 bytes
コンパイル時間 1,842 ms
コンパイル使用メモリ 71,628 KB
実行使用メモリ 57,244 KB
最終ジャッジ日時 2023-09-18 06:22:27
合計ジャッジ時間 5,373 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
55,584 KB
testcase_01 AC 122 ms
57,244 KB
testcase_02 AC 121 ms
55,560 KB
testcase_03 AC 123 ms
55,668 KB
testcase_04 AC 119 ms
55,820 KB
testcase_05 AC 120 ms
55,344 KB
testcase_06 AC 121 ms
55,820 KB
testcase_07 AC 119 ms
55,460 KB
testcase_08 AC 121 ms
56,112 KB
testcase_09 AC 121 ms
55,728 KB
testcase_10 AC 118 ms
55,672 KB
testcase_11 AC 120 ms
55,944 KB
testcase_12 AC 122 ms
55,832 KB
testcase_13 AC 118 ms
55,892 KB
testcase_14 AC 118 ms
55,572 KB
testcase_15 AC 121 ms
55,788 KB
testcase_16 AC 119 ms
55,992 KB
testcase_17 AC 121 ms
55,668 KB
testcase_18 AC 120 ms
55,856 KB
testcase_19 AC 121 ms
55,760 KB
testcase_20 AC 120 ms
55,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static Scanner scan = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        BigInteger a = scan.nextBigInteger();
        BigInteger b = scan.nextBigInteger();
        BigInteger c = gcd(a.add(b),a.multiply(b));
        System.out.println(c);
    }

    private static BigInteger gcd(BigInteger a, BigInteger b) {
        if(a.compareTo(b) > 0) {
            gcd(b, a);
        }
        BigInteger tmp = BigInteger.ZERO;
        while(b.compareTo(BigInteger.ZERO) > 0) {
            tmp = a.remainder(b);
            a = b;
            b = tmp;
        }
        return a;
    }   
}
0