結果

問題 No.1581 Multiple Sequence
ユーザー tentententen
提出日時 2023-04-25 18:26:18
言語 Java21
(openjdk 21)
結果
AC  
実行時間 606 ms / 2,000 ms
コード長 2,078 bytes
コンパイル時間 2,725 ms
コンパイル使用メモリ 91,828 KB
実行使用メモリ 50,400 KB
最終ジャッジ日時 2024-04-26 22:44:28
合計ジャッジ時間 12,157 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
36,776 KB
testcase_01 AC 51 ms
37,240 KB
testcase_02 AC 478 ms
48,040 KB
testcase_03 AC 543 ms
49,268 KB
testcase_04 AC 201 ms
42,548 KB
testcase_05 AC 564 ms
49,524 KB
testcase_06 AC 291 ms
44,256 KB
testcase_07 AC 190 ms
42,356 KB
testcase_08 AC 245 ms
43,516 KB
testcase_09 AC 518 ms
49,044 KB
testcase_10 AC 374 ms
46,176 KB
testcase_11 AC 127 ms
40,768 KB
testcase_12 AC 261 ms
43,828 KB
testcase_13 AC 56 ms
37,180 KB
testcase_14 AC 556 ms
49,280 KB
testcase_15 AC 417 ms
46,632 KB
testcase_16 AC 145 ms
41,128 KB
testcase_17 AC 606 ms
50,144 KB
testcase_18 AC 117 ms
40,384 KB
testcase_19 AC 493 ms
48,280 KB
testcase_20 AC 501 ms
48,472 KB
testcase_21 AC 553 ms
49,264 KB
testcase_22 AC 348 ms
45,612 KB
testcase_23 AC 601 ms
50,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    static int[] dp;
    static final int MOD = 1000000007;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        dp = new int[n + 1];
        Arrays.fill(dp, -1);
        dp[0] = 1;
        System.out.println(dfw(n));
    }
    
    static int dfw(int v) {
        if (dp[v] < 0) {
            dp[v] = 0;
            for (int i = 1; i <= Math.sqrt(v); i++) {
                if (v % i == 0) {
                    dp[v] += dfw(v / i - 1);
                    dp[v] %= MOD;
                    if (i * i < v) {
                        dp[v] += dfw(i - 1);
                        dp[v] %= MOD;
                    }
                }
            }
        }
        return dp[v];
    } 
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    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 int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0