結果
問題 | No.1973 Divisor Sequence |
ユーザー | ygd. |
提出日時 | 2022-06-11 00:10:49 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 103 ms / 2,000 ms |
コード長 | 2,257 bytes |
コンパイル時間 | 152 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 75,648 KB |
最終ジャッジ日時 | 2024-09-21 07:32:40 |
合計ジャッジ時間 | 2,270 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
53,364 KB |
testcase_01 | AC | 36 ms
54,328 KB |
testcase_02 | AC | 44 ms
59,500 KB |
testcase_03 | AC | 42 ms
58,244 KB |
testcase_04 | AC | 40 ms
58,548 KB |
testcase_05 | AC | 46 ms
58,588 KB |
testcase_06 | AC | 38 ms
53,372 KB |
testcase_07 | AC | 42 ms
58,344 KB |
testcase_08 | AC | 41 ms
58,400 KB |
testcase_09 | AC | 40 ms
58,920 KB |
testcase_10 | AC | 43 ms
60,048 KB |
testcase_11 | AC | 38 ms
53,372 KB |
testcase_12 | AC | 41 ms
59,704 KB |
testcase_13 | AC | 43 ms
60,884 KB |
testcase_14 | AC | 47 ms
62,496 KB |
testcase_15 | AC | 40 ms
59,088 KB |
testcase_16 | AC | 40 ms
59,496 KB |
testcase_17 | AC | 44 ms
60,672 KB |
testcase_18 | AC | 45 ms
62,376 KB |
testcase_19 | AC | 44 ms
60,360 KB |
testcase_20 | AC | 43 ms
58,788 KB |
testcase_21 | AC | 41 ms
58,236 KB |
testcase_22 | AC | 40 ms
59,980 KB |
testcase_23 | AC | 103 ms
75,648 KB |
testcase_24 | AC | 47 ms
61,688 KB |
ソースコード
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 prime_factorize(n): ret = [] #if n == 1: # ret.append((1,1)) # return ret cnt = 0 while n % 2 == 0: cnt += 1 n //= 2 if cnt > 0: ret.append((2,cnt)) i = 3 while i * i <= n: cnt = 0 while n % i == 0: cnt += 1 n //= i else: if cnt != 0: #cnt==0の時は追加しない ret.append((i,cnt)) i += 2 if n != 1: ret.append((n,1)) return ret #(素因数、何乗) 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 = prime_factorize(M) # val_to_id = {} # for i,v in enumerate(d): # val_to_id[v] = i #print(d) ans = 1 for p,n in d: n += 1 A = [[0]*n for _ in range(n)] for i in range(n): for j in range(n-i): 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) temp = 0 for i in range(n): temp += nv[i][0] temp %= MOD ans *= temp ans %= MOD print(ans%MOD) if __name__ == '__main__': main()