結果
問題 | No.442 和と積 |
ユーザー | htensai |
提出日時 | 2019-11-19 12:48:11 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,711 bytes |
コンパイル時間 | 2,532 ms |
コンパイル使用メモリ | 80,104 KB |
実行使用メモリ | 62,504 KB |
最終ジャッジ日時 | 2024-04-14 09:24:51 |
合計ジャッジ時間 | 8,800 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 206 ms
62,504 KB |
testcase_01 | AC | 134 ms
54,268 KB |
testcase_02 | AC | 134 ms
53,976 KB |
testcase_03 | AC | 174 ms
55,240 KB |
testcase_04 | AC | 137 ms
53,988 KB |
testcase_05 | AC | 136 ms
53,848 KB |
testcase_06 | AC | 135 ms
54,116 KB |
testcase_07 | AC | 180 ms
54,600 KB |
testcase_08 | AC | 135 ms
54,024 KB |
testcase_09 | AC | 155 ms
54,560 KB |
testcase_10 | AC | 135 ms
54,208 KB |
testcase_11 | AC | 134 ms
54,216 KB |
testcase_12 | AC | 138 ms
54,060 KB |
testcase_13 | AC | 137 ms
54,288 KB |
testcase_14 | AC | 134 ms
54,124 KB |
testcase_15 | AC | 146 ms
54,348 KB |
testcase_16 | AC | 135 ms
53,932 KB |
testcase_17 | AC | 134 ms
53,864 KB |
testcase_18 | AC | 137 ms
54,244 KB |
testcase_19 | AC | 151 ms
54,352 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> pMap = new HashMap<>(); for (long i = 2; i <= Math.sqrt(a); i++) { while (a % i == 0) { if (pMap.containsKey(i)) { pMap.put(i, pMap.get(i) + 1); } else { pMap.put(i, 1); } a /= i; } } if (a != 1) { if (pMap.containsKey(a)) { pMap.put(a, pMap.get(a) + 1); } else { pMap.put(a, 1); } } for (long i = 2; i <= Math.sqrt(b); i++) { while (b % i == 0) { if (pMap.containsKey(i)) { pMap.put(i, pMap.get(i) + 1); } else { pMap.put(i, 1); } b /= i; } } if (b != 1) { if (pMap.containsKey(b)) { pMap.put(b, pMap.get(b) + 1); } else { pMap.put(b, 1); } } HashMap<Long, Integer> sMap = new HashMap<>(); for (long i = 2; i <= Math.sqrt(c); i++) { while (c % i == 0) { if (sMap.containsKey(i)) { sMap.put(i, sMap.get(i) + 1); } else { sMap.put(i, 1); } c /= i; } } if (c != 1) { if (sMap.containsKey(c)) { sMap.put(c, pMap.get(c) + 1); } else { sMap.put(c, 1); } } long ans = 1; for (Map.Entry<Long, Integer> entry : sMap.entrySet()) { long x = entry.getKey(); if (pMap.containsKey(x)) { ans *= (long)(Math.pow(x, Math.min(pMap.get(x), entry.getValue()))); } } System.out.println(ans); } }