結果

問題 No.1737 One to N
ユーザー merlinmerlin
提出日時 2021-11-12 22:17:37
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,007 ms / 2,000 ms
コード長 716 bytes
コンパイル時間 2,304 ms
コンパイル使用メモリ 76,092 KB
実行使用メモリ 130,452 KB
最終ジャッジ日時 2024-05-04 09:17:04
合計ジャッジ時間 31,469 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 914 ms
130,356 KB
testcase_01 AC 918 ms
130,256 KB
testcase_02 AC 920 ms
130,332 KB
testcase_03 AC 911 ms
130,248 KB
testcase_04 AC 932 ms
130,268 KB
testcase_05 AC 912 ms
130,220 KB
testcase_06 AC 942 ms
130,344 KB
testcase_07 AC 923 ms
130,212 KB
testcase_08 AC 940 ms
130,156 KB
testcase_09 AC 949 ms
130,324 KB
testcase_10 AC 923 ms
130,452 KB
testcase_11 AC 940 ms
130,272 KB
testcase_12 AC 929 ms
130,144 KB
testcase_13 AC 919 ms
130,140 KB
testcase_14 AC 920 ms
130,172 KB
testcase_15 AC 928 ms
130,288 KB
testcase_16 AC 918 ms
130,256 KB
testcase_17 AC 914 ms
130,388 KB
testcase_18 AC 931 ms
130,268 KB
testcase_19 AC 925 ms
130,384 KB
testcase_20 AC 903 ms
130,316 KB
testcase_21 AC 912 ms
130,164 KB
testcase_22 AC 1,007 ms
130,280 KB
testcase_23 AC 905 ms
130,332 KB
testcase_24 AC 924 ms
130,256 KB
testcase_25 AC 892 ms
130,252 KB
testcase_26 AC 890 ms
130,316 KB
testcase_27 AC 935 ms
130,248 KB
testcase_28 AC 932 ms
130,380 KB
testcase_29 AC 895 ms
130,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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]);
    }
}
0