結果

問題 No.1973 Divisor Sequence
ユーザー terasaterasa
提出日時 2022-06-11 00:22:07
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 2,276 bytes
コンパイル時間 186 ms
コンパイル使用メモリ 81,704 KB
実行使用メモリ 83,792 KB
最終ジャッジ日時 2023-10-21 06:20:58
合計ジャッジ時間 5,195 ms
ジャッジサーバーID
(参考情報)
judge11 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
61,788 KB
testcase_01 AC 46 ms
55,748 KB
testcase_02 AC 114 ms
72,724 KB
testcase_03 AC 75 ms
66,388 KB
testcase_04 AC 114 ms
72,644 KB
testcase_05 AC 76 ms
61,532 KB
testcase_06 AC 74 ms
66,416 KB
testcase_07 AC 104 ms
66,416 KB
testcase_08 AC 96 ms
66,416 KB
testcase_09 AC 106 ms
72,644 KB
testcase_10 AC 131 ms
72,676 KB
testcase_11 AC 97 ms
72,644 KB
testcase_12 AC 100 ms
66,416 KB
testcase_13 AC 77 ms
66,444 KB
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import pypyjit
import itertools
import heapq
import math
from collections import deque, defaultdict
import bisect

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
pypyjit.set_param('max_unroll_recursion=-1')


def index_lt(a, x):
    'return largest index s.t. A[i] < x or -1 if it does not exist'
    return bisect.bisect_left(a, x) - 1


def index_le(a, x):
    'return largest index s.t. A[i] <= x or -1 if it does not exist'
    return bisect.bisect_right(a, x) - 1


def index_gt(a, x):
    'return smallest index s.t. A[i] > x or len(a) if it does not exist'
    return bisect.bisect_right(a, x)


def index_ge(a, x):
    'return smallest index s.t. A[i] >= x or len(a) if it does not exist'
    return bisect.bisect_left(a, x)


class Matpow:
    def __init__(self, N, A, p):
        self.N = N
        self.A = A
        self.p = p
        self.digit = 60
        self.doubling = [None] * self.digit

        self.doubling[0] = A
        for i in range(1, self.digit):
            self.doubling[i] = self.mul(self.doubling[i - 1], self.doubling[i - 1])

    def pow(self, n):
        E = [[1 if i == j else 0 for j in range(self.N)] for i in range(self.N)]
        acc = E
        for k in range(self.digit):
            if n & (1 << k):
                acc = self.mul(acc, self.doubling[k])
        return acc

    def mul(self, A, B):
        C = [[0 for _ in range(self.N)] for _ in range(self.N)]
        for i in range(self.N):
            for j in range(self.N):
                for k in range(self.N):
                    C[i][j] += A[i][k] * B[k][j]
                    C[i][j] %= self.p
        return C


N, M = map(int, input().split())
mod = 10 ** 9 + 7


def divs(n):
    d = []
    for i in range(1, n + 1):
        if i * i > n:
            break
        if i * i == n:
            d.append(i)
            break
        if n % i == 0:
            d.append(i)
            d.append(n // i)
    return sorted(d)


D = divs(M)
idx = {}
for i, n in enumerate(D):
    idx[n] = i
A = []
for d in D:
    a = [0] * len(D)
    for n in divs(M // d):
        a[idx[n]] = 1
    A.append(a)

An = Matpow(len(D), A, mod).pow(N - 1)
ans = 0
for i in range(len(D)):
    for j in range(len(D)):
        ans += An[i][j]
        ans %= mod
print(ans)
0