結果

問題 No.1049 Zero (Exhaust)
ユーザー ああいい
提出日時 2021-12-05 19:28:19
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 526 bytes
コンパイル時間 221 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-07-07 08:41:11
合計ジャッジ時間 1,536 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

P,K = list(map(int,input().split()))

p = 10 ** 9 + 7

def multi(l,m):
    a,b = l[0]
    c,d = l[1]
    x,y = m[0]
    z,w = m[1]
    return [[(a * x + b * z) % p,(a * y + b * w) % p],
            [(c * x + d * z) % p,(c * y + d * w) % p]]

A = [[P+1,2],[P-1,2 * P - 2]]
c = 1
while 2 ** c <= K:
    c += 1
Mat = [0] * (c + 1)
Mat[0] = [[1,0],[0,1]]
Mat[1] = A
for i in range(2,c + 1):
    Mat[i] = multi(Mat[i-1],Mat[i-1])
E = Mat[0]
for i in range(0,c+1):
    if K & (1 << i):
        E = multi(E,Mat[i+1])
print(E[0][0])
0