結果
| 問題 |
No.300 平方数
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2022-07-30 09:46:05 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 86 ms / 1,000 ms |
| コード長 | 1,415 bytes |
| コンパイル時間 | 2,386 ms |
| コンパイル使用メモリ | 78,708 KB |
| 実行使用メモリ | 37,956 KB |
| 最終ジャッジ日時 | 2024-07-20 05:20:57 |
| 合計ジャッジ時間 | 6,384 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 43 |
ソースコード
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
long x = sc.nextLong();
HashMap<Long, Integer> counts = new HashMap<>();
for (long i = 2; i <= Math.sqrt(x); i++) {
while (x % i == 0) {
counts.put(i, counts.getOrDefault(i, 0) + 1);
x /= i;
}
}
if (x > 1) {
counts.put(x, counts.getOrDefault(x, 0) + 1);
}
long ans = 1;
for (long y : counts.keySet()) {
if (counts.get(y) % 2 == 1) {
ans *= y;
}
}
System.out.println(ans);
}
}
class Scanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
public Scanner() throws Exception {
}
public int nextInt() throws Exception {
return Integer.parseInt(next());
}
public long nextLong() throws Exception {
return Long.parseLong(next());
}
public double nextDouble() throws Exception {
return Double.parseDouble(next());
}
public String next() throws Exception {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
}
tenten