結果
問題 | No.300 平方数 |
ユーザー |
![]() |
提出日時 | 2018-11-03 21:46:39 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 760 ms / 1,000 ms |
コード長 | 718 bytes |
コンパイル時間 | 2,304 ms |
コンパイル使用メモリ | 76,036 KB |
実行使用メモリ | 139,432 KB |
最終ジャッジ日時 | 2024-11-20 19:36:23 |
合計ジャッジ時間 | 22,515 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 43 |
ソースコード
import java.util.Map; import java.util.Scanner; import java.util.TreeMap; public class Main { @SuppressWarnings("resource") public static void main(String args[]) { Scanner scanner = new Scanner(System.in); long x = scanner.nextLong(); Map<Long, Integer> map = prime_fact(x); long ans = 1; for (long key : map.keySet()) { if (map.get(key) % 2 == 1) { ans *= key; } } System.out.println(ans); } private static Map<Long, Integer> prime_fact(long x) { Map<Long, Integer> map = new TreeMap<>(); double d = Math.sqrt(x); for (int i = 2; i <= d; i++) { int cnt = 0; while (x % i == 0) { x /= i; cnt++; } map.put((long) i, cnt); } map.put(x, 1); return map; } }