結果
問題 | No.442 和と積 |
ユーザー | htensai |
提出日時 | 2019-12-10 11:12:29 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,107 bytes |
コンパイル時間 | 3,493 ms |
コンパイル使用メモリ | 76,340 KB |
実行使用メモリ | 61,584 KB |
最終ジャッジ日時 | 2023-09-06 04:49:31 |
合計ジャッジ時間 | 9,618 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 186 ms
57,152 KB |
testcase_01 | AC | 121 ms
55,784 KB |
testcase_02 | AC | 117 ms
55,368 KB |
testcase_03 | AC | 159 ms
57,068 KB |
testcase_04 | AC | 120 ms
55,608 KB |
testcase_05 | AC | 119 ms
55,864 KB |
testcase_06 | AC | 115 ms
56,736 KB |
testcase_07 | AC | 160 ms
57,160 KB |
testcase_08 | AC | 113 ms
55,948 KB |
testcase_09 | AC | 140 ms
55,868 KB |
testcase_10 | AC | 123 ms
55,888 KB |
testcase_11 | AC | 121 ms
56,076 KB |
testcase_12 | AC | 120 ms
55,896 KB |
testcase_13 | AC | 120 ms
55,780 KB |
testcase_14 | AC | 123 ms
55,840 KB |
testcase_15 | AC | 127 ms
56,212 KB |
testcase_16 | AC | 118 ms
55,848 KB |
testcase_17 | AC | 130 ms
57,928 KB |
testcase_18 | AC | 123 ms
55,828 KB |
testcase_19 | AC | 135 ms
56,040 KB |
testcase_20 | TLE | - |
ソースコード
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> mapX = new HashMap<>(); for (long i = 2; i <= Math.sqrt(c); i++) { while (c % i == 0) { if (mapX.containsKey(i)) { mapX.put(i, mapX.get(i) + 1); } else { mapX.put(i, 1); } c /= i; } } if (c != 1) { if (mapX.containsKey(c)) { mapX.put(c, mapX.get(c) + 1); } else { mapX.put(c, 1); } } HashMap<Long, Integer> mapY = new HashMap<>(); for (long i = 2; i <= Math.sqrt(a); i++) { while (a % i == 0) { if (mapY.containsKey(i)) { mapY.put(i, mapY.get(i) + 1); } else { mapY.put(i, 1); } a /= i; } } if (a != 1) { if (mapY.containsKey(a)) { mapY.put(a, mapY.get(a) + 1); } else { mapY.put(a, 1); } } for (long i = 2; i <= Math.sqrt(b); i++) { while (b % i == 0) { if (mapY.containsKey(i)) { mapY.put(i, mapY.get(i) + 1); } else { mapY.put(i, 1); } b /= i; } } if (b != 1) { if (mapY.containsKey(b)) { mapY.put(b, mapY.get(b) + 1); } else { mapY.put(b, 1); } } long ans = 1; for (Map.Entry<Long, Integer> entry : mapX.entrySet()) { if (mapY.containsKey(entry.getKey())) { ans *= (long)(Math.pow(entry.getKey(), Math.min(entry.getValue(), mapY.get(entry.getKey())))); } } System.out.println(ans); } }