結果

問題 No.442 和と積
ユーザー takeya_okino
提出日時 2019-08-21 22:05:37
言語 Java
(openjdk 23)
結果
AC  
実行時間 140 ms / 1,000 ms
コード長 416 bytes
コンパイル時間 2,353 ms
コンパイル使用メモリ 74,264 KB
実行使用メモリ 41,696 KB
最終ジャッジ日時 2024-10-10 02:01:43
合計ジャッジ時間 6,330 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

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