結果

問題 No.442 和と積
コンテスト
ユーザー jp_ste
提出日時 2016-11-11 23:43:43
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 58 ms / 1,000 ms
コード長 774 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,613 ms
コンパイル使用メモリ 82,064 KB
実行使用メモリ 42,112 KB
最終ジャッジ日時 2026-03-26 05:06:04
合計ジャッジ時間 3,513 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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