結果

問題 No.442 和と積
ユーザー kohaku_kohaku
提出日時 2016-11-11 23:42:21
言語 Java
(openjdk 23)
結果
AC  
実行時間 137 ms / 1,000 ms
コード長 852 bytes
コンパイル時間 2,251 ms
コンパイル使用メモリ 77,448 KB
実行使用メモリ 41,412 KB
最終ジャッジ日時 2024-07-04 22:35:00
合計ジャッジ時間 5,682 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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 y = 0;
        long m = A;
        long n = B;
        while(true){
            y = m%n;
            if(y==0){
                break;
            }
            m=n;
            n=y;
        }

        long S = (A+B)/n;
        long a = A/n;
        long x = 0;
        while(true){
            x = S%a;
            if(x==0){
                break;
            }
            S=a;
            a=x;
        }

        S = (A+B)/n;
        long b = B;
        while(true){
            x = S%b;
            if(x==0){
                break;
            }
            S=b;
            b=x;
        }
        System.out.println(n*a*b);
    }
}
0