結果

問題 No.442 和と積
ユーザー tentententen
提出日時 2020-09-10 19:55:57
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 715 bytes
コンパイル時間 2,874 ms
コンパイル使用メモリ 72,972 KB
実行使用メモリ 60,184 KB
最終ジャッジ日時 2023-08-25 13:10:45
合計ジャッジ時間 8,882 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
56,612 KB
testcase_01 AC 120 ms
56,008 KB
testcase_02 AC 120 ms
55,652 KB
testcase_03 AC 124 ms
56,016 KB
testcase_04 AC 119 ms
55,756 KB
testcase_05 AC 120 ms
55,828 KB
testcase_06 AC 120 ms
55,392 KB
testcase_07 AC 125 ms
55,664 KB
testcase_08 AC 120 ms
56,316 KB
testcase_09 AC 137 ms
56,224 KB
testcase_10 AC 120 ms
56,252 KB
testcase_11 AC 121 ms
56,120 KB
testcase_12 AC 122 ms
55,704 KB
testcase_13 AC 122 ms
55,756 KB
testcase_14 AC 121 ms
55,672 KB
testcase_15 AC 120 ms
55,420 KB
testcase_16 AC 121 ms
55,812 KB
testcase_17 AC 119 ms
55,908 KB
testcase_18 AC 120 ms
55,860 KB
testcase_19 AC 130 ms
56,560 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;
    	HashMap<Long, Integer> map = new HashMap<>();
    	long ans = 1;
    	for (long i = 2; i <= Math.sqrt(c); i++) {
    	    while (c % i == 0) {
    	        if (a % i == 0) {
    	            ans *= i;
    	            a /= i;
    	        } else if (b % i == 0) {
    	            ans *= i;
    	            b /= i;
    	        }
    	        c /= i;
    	    }
    	}
    	if (a % c == 0) {
    	    ans *= c;
    	} else if (b % c == 0) {
    	    ans += c;
    	}
    	System.out.println(ans);
    }
}
0