結果

問題 No.442 和と積
ユーザー tentententen
提出日時 2020-09-12 23:07:33
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 678 bytes
コンパイル時間 2,308 ms
コンパイル使用メモリ 72,596 KB
実行使用メモリ 60,224 KB
最終ジャッジ日時 2023-08-30 19:33:52
合計ジャッジ時間 8,581 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
56,316 KB
testcase_01 AC 119 ms
56,852 KB
testcase_02 AC 122 ms
56,364 KB
testcase_03 AC 127 ms
56,084 KB
testcase_04 AC 121 ms
55,996 KB
testcase_05 AC 122 ms
55,848 KB
testcase_06 AC 118 ms
56,372 KB
testcase_07 AC 126 ms
56,096 KB
testcase_08 AC 121 ms
56,116 KB
testcase_09 AC 138 ms
56,360 KB
testcase_10 AC 123 ms
56,320 KB
testcase_11 AC 122 ms
56,244 KB
testcase_12 AC 120 ms
55,920 KB
testcase_13 AC 118 ms
56,108 KB
testcase_14 AC 119 ms
56,612 KB
testcase_15 AC 121 ms
56,048 KB
testcase_16 AC 121 ms
56,120 KB
testcase_17 AC 126 ms
55,828 KB
testcase_18 AC 121 ms
55,896 KB
testcase_19 AC 126 ms
55,812 KB
testcase_20 TLE -
権限があれば一括ダウンロードができます

ソースコード

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 c = a + b;
    	long ans = 1;
    	for (long i = 2; i <= Math.sqrt(c); i++) {
    	    while (c % i == 0) {
    	        if (a % i == 0) {
    	           a /= i;
    	           ans *= i;
    	        } else if (b % i == 0) {
    	            b /= i;
    	            ans *= i;
    	        }
    	        c /= i;
    	    }
    	}
    	if  (c > 1 && a % c == 0) {
    	    ans *= c;
    	} else if (c > 1 && b % c == 0) {
    	    ans *= c;
    	}
    	System.out.println(ans);
	}
}
0