結果

問題 No.1973 Divisor Sequence
ユーザー ygd.ygd.
提出日時 2022-06-10 22:13:37
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,954 bytes
コンパイル時間 153 ms
コンパイル使用メモリ 81,708 KB
実行使用メモリ 82,360 KB
最終ジャッジ日時 2023-10-21 05:19:03
合計ジャッジ時間 4,699 ms
ジャッジサーバーID
(参考情報)
judge15 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,312 KB
testcase_01 AC 38 ms
53,312 KB
testcase_02 AC 62 ms
65,980 KB
testcase_03 AC 52 ms
61,836 KB
testcase_04 AC 62 ms
65,980 KB
testcase_05 AC 55 ms
59,140 KB
testcase_06 AC 57 ms
61,876 KB
testcase_07 AC 60 ms
61,876 KB
testcase_08 AC 64 ms
61,876 KB
testcase_09 AC 62 ms
65,980 KB
testcase_10 AC 66 ms
61,856 KB
testcase_11 AC 60 ms
65,980 KB
testcase_12 AC 62 ms
61,876 KB
testcase_13 AC 54 ms
61,856 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
#input = sys.stdin.readline
input = sys.stdin.buffer.readline #文字列はダメ
#sys.setrecursionlimit(1000000)
#import bisect
#import itertools
#import random
#from heapq import heapify, heappop, heappush
#from collections import defaultdict 
#from collections import deque
#import copy
#import math
#from functools import lru_cache
#@lru_cache(maxsize=None)
MOD = pow(10,9) + 7
#MOD = 998244353
#dx = [1,0,-1,0]
#dy = [0,1,0,-1]
#dx8 = [1,1,0,-1,-1,-1,0,1]
#dy8 = [0,1,1,1,0,-1,-1,-1]

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

def mat_dot(A, B, MOD=pow(10,9)+7):
  #A:n*m行列, B:m*l行列
  n, m, l = len(A), len(A[0]), len(B[0])
  X = [[0]*l for i in range(n)]
  for i in range(n):
    for j in range(l):
      temp = 0
      for k in range(m):
        temp = (temp + A[i][k] * B[k][j]) % MOD
      X[i][j] = temp
  return X
 
def mat_pow(A, x, MOD):
  #A^x
  n = len(A)
  X = [[0] * n for i in range(n)]
  for i in range(n):
    X[i][i] = 1
  for i in range(x.bit_length()):
    if (x>>i)&1:
      X = mat_dot(X, A, MOD)
    A = mat_dot(A, A, MOD)
  return X

def main():
    N,M = map(int,input().split())
    d = make_divisors(M)
    # val_to_id = {}
    # for i,v in enumerate(d):
    #     val_to_id[v] = i
    #print(d)
    n = len(d)

    A = [[0]*n for _ in range(n)]
    for i in range(n):
        base = d[i]
        for j,v in enumerate(d):
            if M%(base*v) == 0:
                A[i][j] = 1
    #print(A)
    
    v = [[0] for _ in range(n)]
    v[0][0] = 1

    X = mat_pow(A,N,MOD)
    #print(X)
    nv = mat_dot(X,v,MOD)
    ans = 0
    for i in range(n):
        ans += nv[i][0]
        ans %= MOD
    print(ans%MOD)



if __name__ == '__main__':
    main()
0