結果
問題 | No.1737 One to N |
ユーザー |
![]() |
提出日時 | 2021-11-12 22:17:37 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 1,195 ms / 2,000 ms |
コード長 | 716 bytes |
コンパイル時間 | 2,292 ms |
コンパイル使用メモリ | 76,272 KB |
実行使用メモリ | 120,680 KB |
最終ジャッジ日時 | 2024-11-25 19:16:52 |
合計ジャッジ時間 | 37,955 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
import java.io.*;import java.util.*;class Main{public static void main(String args[])throws Exception{BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));StringBuilder sb=new StringBuilder();int N=300000,i,j,ans[]=new int[N+1];ArrayList<Integer> fac[]=new ArrayList[N+1];for(i=0;i<=N;i++){fac[i]=new ArrayList<>();ans[i]=i;}for(i=2;i<=N;i++)for(j=2*i;j<=N;j+=i) fac[j].add(i);ans[1]=0;for(i=2;i<=N;i++)for(int x:fac[i]) ans[i]=Math.min(ans[i],ans[x]+i/x);int n=Integer.parseInt(bu.readLine());System.out.println(ans[n]);}}