結果
| 問題 |
No.1737 One to N
|
| コンテスト | |
| ユーザー |
ks2m
|
| 提出日時 | 2021-11-12 21:33:43 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 135 ms / 2,000 ms |
| コード長 | 817 bytes |
| コンパイル時間 | 2,422 ms |
| コンパイル使用メモリ | 79,200 KB |
| 実行使用メモリ | 54,324 KB |
| 最終ジャッジ日時 | 2024-11-25 12:25:13 |
| 合計ジャッジ時間 | 7,341 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.close();
if (n == 1) {
System.out.println(0);
} else {
Map<Integer, Integer> soinsu = bunkai(n);
int ans = 0;
for (int k : soinsu.keySet()) {
ans += k * soinsu.get(k);
}
System.out.println(ans);
}
}
static Map<Integer, Integer> bunkai(int n) {
Map<Integer, Integer> soinsu = new HashMap<>();
int end = (int) Math.sqrt(n);
int d = 2;
while (n > 1) {
if (n % d == 0) {
n /= d;
soinsu.put(d, soinsu.getOrDefault(d, 0) + 1);
end = (int) Math.sqrt(n);
} else {
if (d > end) {
d = n - 1;
}
d++;
}
}
return soinsu;
}
}
ks2m