結果

問題 No.1973 Divisor Sequence
ユーザー tentententen
提出日時 2024-04-02 14:08:50
言語 Java21
(openjdk 21)
結果
MLE  
実行時間 -
コード長 2,710 bytes
コンパイル時間 2,482 ms
コンパイル使用メモリ 79,392 KB
実行使用メモリ 747,784 KB
最終ジャッジ日時 2024-04-02 14:08:59
合計ジャッジ時間 8,389 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
53,980 KB
testcase_01 AC 55 ms
51,968 KB
testcase_02 AC 98 ms
55,544 KB
testcase_03 AC 70 ms
54,644 KB
testcase_04 AC 102 ms
55,776 KB
testcase_05 AC 76 ms
55,136 KB
testcase_06 AC 85 ms
55,388 KB
testcase_07 AC 81 ms
55,152 KB
testcase_08 AC 79 ms
55,060 KB
testcase_09 AC 97 ms
55,544 KB
testcase_10 AC 126 ms
56,020 KB
testcase_11 AC 94 ms
55,396 KB
testcase_12 AC 80 ms
55,152 KB
testcase_13 AC 68 ms
54,644 KB
testcase_14 AC 1,722 ms
66,248 KB
testcase_15 AC 134 ms
57,072 KB
testcase_16 AC 104 ms
55,636 KB
testcase_17 AC 125 ms
56,536 KB
testcase_18 AC 152 ms
57,044 KB
testcase_19 AC 122 ms
56,532 KB
testcase_20 AC 102 ms
55,888 KB
testcase_21 AC 80 ms
55,060 KB
testcase_22 AC 98 ms
55,544 KB
testcase_23 AC 141 ms
57,040 KB
testcase_24 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static final int MOD = 1000000007;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt() + 1;
        long m = sc.nextLong();
        List<Long> divs = new ArrayList<>();
        for (long i = 1; i * i <= m; i++) {
            if (m % i == 0) {
                divs.add(i);
                if (i * i < m) {
                    divs.add(m / i);
                }
            }
        }
        int size = divs.size();
        long[][][] matrix = new long[20][size][size];
        for (int i = 0; i < size; i++) {
            long current = m / divs.get(i);
            for (int j = 0; j < size; j++) {
                if (current % divs.get(j) == 0) {
                    matrix[0][i][j] = 1;
                }
            }
        }
        for (int i = 1; i < 20; i++) {
            for (int a = 0; a < size; a++) {
                for (int b = 0; b < size; b++) {
                    for (int c = 0; c < size; c++) {
                        matrix[i][a][c] += matrix[i - 1][a][b] * matrix[i - 1][b][c] % MOD;
                        matrix[i][a][c] %= MOD;
                    }
                }
            }
        }
        long[] ans = new long[size];
        ans[0] = 1;
        for (int i = 19; i >= 0; i--) {
            if (n < (1 << i)) {
                continue;
            }
            n -= (1 << i);
            long[] next = new long[size];
            for (int a = 0; a < size; a++) {
                for (int b = 0; b <size; b++) {
                    next[a] += matrix[i][a][b] * ans[b] % MOD;
                    next[a] %= MOD;
                }
            }
            ans = next;
        }
        System.out.println(ans[0]);
    }
}
class Scanner {
    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
        } catch (Exception e) {
            
        }
    }
    
    public int nextInt() {
        return Integer.parseInt(next());
    }
    
    public long nextLong() {
        return Long.parseLong(next());
    }
    
    public double nextDouble() {
        return Double.parseDouble(next());
    }
    
    public String next() {
        try {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return st.nextToken();
        }
    }
    
}
0