結果

問題 No.442 和と積
ユーザー takeya_okinotakeya_okino
提出日時 2019-08-21 22:05:37
言語 Java21
(openjdk 21)
結果
AC  
実行時間 135 ms / 1,000 ms
コード長 416 bytes
コンパイル時間 2,031 ms
コンパイル使用メモリ 74,304 KB
実行使用メモリ 41,764 KB
最終ジャッジ日時 2024-04-18 08:46:34
合計ジャッジ時間 5,841 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
41,276 KB
testcase_01 AC 128 ms
41,288 KB
testcase_02 AC 128 ms
41,092 KB
testcase_03 AC 129 ms
41,056 KB
testcase_04 AC 130 ms
41,164 KB
testcase_05 AC 123 ms
41,400 KB
testcase_06 AC 128 ms
41,196 KB
testcase_07 AC 117 ms
40,080 KB
testcase_08 AC 115 ms
39,864 KB
testcase_09 AC 128 ms
41,180 KB
testcase_10 AC 127 ms
41,512 KB
testcase_11 AC 128 ms
41,232 KB
testcase_12 AC 116 ms
41,312 KB
testcase_13 AC 130 ms
41,308 KB
testcase_14 AC 124 ms
40,280 KB
testcase_15 AC 133 ms
41,668 KB
testcase_16 AC 131 ms
41,764 KB
testcase_17 AC 115 ms
39,956 KB
testcase_18 AC 135 ms
41,364 KB
testcase_19 AC 132 ms
41,352 KB
testcase_20 AC 132 ms
41,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    long g = gcd(a, b);
    long a2 = a / g;
    long b2 = b / g;
    long g2 = gcd(a2 + b2, g);
    System.out.println(g * g2);
  }

  public static long gcd(long a, long b) {
    if(b == 0) return a;
    return gcd(b, (a % b));
  }
}
0