結果
問題 | No.1737 One to N |
ユーザー | tenten |
提出日時 | 2021-11-15 09:01:51 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 81 ms / 2,000 ms |
コード長 | 1,355 bytes |
コンパイル時間 | 3,907 ms |
コンパイル使用メモリ | 76,672 KB |
実行使用メモリ | 38,052 KB |
最終ジャッジ日時 | 2024-12-14 05:09:58 |
合計ジャッジ時間 | 5,359 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); if (n == 1) { System.out.println(0); } else { System.out.println(getScore(n)); } } static int getScore(int x) { int ans = x; for (int i = 2; i <= Math.sqrt(x); i++) { if (x % i == 0) { ans = Math.min(ans, getScore(i) + getScore(x / i)); } } return 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 nextLine() throws Exception { return br.readLine(); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }