結果
問題 | No.1063 ルートの計算 / Sqrt Calculation |
ユーザー | tenten |
提出日時 | 2020-08-20 14:47:48 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 155 ms / 2,000 ms |
コード長 | 990 bytes |
コンパイル時間 | 3,417 ms |
コンパイル使用メモリ | 86,200 KB |
実行使用メモリ | 42,416 KB |
最終ジャッジ日時 | 2024-04-21 11:31:52 |
合計ジャッジ時間 | 6,987 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 142 ms
42,076 KB |
testcase_01 | AC | 133 ms
41,856 KB |
testcase_02 | AC | 142 ms
42,128 KB |
testcase_03 | AC | 136 ms
42,156 KB |
testcase_04 | AC | 155 ms
42,124 KB |
testcase_05 | AC | 155 ms
42,204 KB |
testcase_06 | AC | 137 ms
41,952 KB |
testcase_07 | AC | 142 ms
42,172 KB |
testcase_08 | AC | 142 ms
42,040 KB |
testcase_09 | AC | 143 ms
42,296 KB |
testcase_10 | AC | 154 ms
42,300 KB |
testcase_11 | AC | 141 ms
42,048 KB |
testcase_12 | AC | 154 ms
42,416 KB |
testcase_13 | AC | 143 ms
42,276 KB |
testcase_14 | AC | 147 ms
42,364 KB |
testcase_15 | AC | 142 ms
42,256 KB |
testcase_16 | AC | 138 ms
41,760 KB |
ソースコード
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int x = n; HashMap<Integer, Integer> map = new HashMap<>(); for (int i = 2; i <= Math.sqrt(x); i++) { while (x % i == 0) { if (map.containsKey(i)) { map.put(i, map.get(i) + 1); } else { map.put(i, 1); } x /= i; } } if (x > 1) { if (map.containsKey(x)) { map.put(x, map.get(x) + 1); } else { map.put(x, 1); } } int ans = 1; for (Map.Entry<Integer, Integer> entry : map.entrySet()) { for (int i = 2; i <= entry.getValue(); i += 2) { ans *= entry.getKey(); } } System.out.println(ans + " " + n / ans / ans); } }