結果

問題 No.891 隣接3項間の漸化式
ユーザー chanpukuchanpuku
提出日時 2019-11-25 23:32:33
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 711 bytes
コンパイル時間 101 ms
コンパイル使用メモリ 10,928 KB
実行使用メモリ 29,768 KB
最終ジャッジ日時 2023-08-05 02:26:34
合計ジャッジ時間 9,810 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
29,768 KB
testcase_01 AC 133 ms
29,612 KB
testcase_02 AC 130 ms
29,672 KB
testcase_03 AC 132 ms
29,648 KB
testcase_04 AC 133 ms
29,684 KB
testcase_05 AC 137 ms
29,620 KB
testcase_06 AC 134 ms
29,564 KB
testcase_07 AC 136 ms
29,668 KB
testcase_08 AC 134 ms
29,592 KB
testcase_09 AC 135 ms
29,584 KB
testcase_10 AC 132 ms
29,568 KB
testcase_11 AC 133 ms
29,596 KB
testcase_12 AC 132 ms
29,672 KB
testcase_13 AC 131 ms
29,540 KB
testcase_14 AC 130 ms
29,528 KB
testcase_15 AC 132 ms
29,628 KB
testcase_16 AC 139 ms
29,572 KB
testcase_17 AC 134 ms
29,688 KB
testcase_18 AC 131 ms
29,568 KB
testcase_19 AC 131 ms
29,628 KB
testcase_20 AC 131 ms
29,676 KB
testcase_21 AC 130 ms
29,528 KB
testcase_22 AC 131 ms
29,596 KB
testcase_23 AC 132 ms
29,648 KB
testcase_24 AC 134 ms
29,584 KB
testcase_25 AC 133 ms
29,708 KB
testcase_26 AC 131 ms
29,600 KB
testcase_27 AC 131 ms
29,580 KB
testcase_28 AC 131 ms
29,592 KB
testcase_29 AC 131 ms
29,632 KB
testcase_30 AC 131 ms
29,572 KB
testcase_31 AC 132 ms
29,560 KB
testcase_32 AC 133 ms
29,560 KB
testcase_33 AC 131 ms
29,724 KB
testcase_34 AC 132 ms
29,672 KB
testcase_35 AC 132 ms
29,588 KB
testcase_36 AC 132 ms
29,532 KB
testcase_37 AC 131 ms
29,712 KB
testcase_38 AC 132 ms
29,600 KB
testcase_39 AC 133 ms
29,616 KB
testcase_40 AC 132 ms
29,604 KB
testcase_41 AC 131 ms
29,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np
a,b,n=map(int,input().split())
m=10**9+7
k=n//2
def dot(A,B):
    n=A.shape[0]
    ans=np.zeros(A.shape,dtype=np.int64)
    A=A%m
    B=B%m
    for i in range(n):
        for j in range(n):
            for k in range(n):
                ans[i,j]=ans[i,j]+(A[i,k]*B[k,j])%m
    return ans            
    
def pow(A,k):
    last=np.eye(A.shape[0])
    cur_A=A
    while True:
        if k==0:
            cur_A=np.eye(A.shape[0])
            break
        elif k%2==0:
            cur_A=dot(cur_A,cur_A)
            k=k/2
        else:
            k=k-1
            last=dot(last,cur_A)
    
    return dot(cur_A,last)

l=1-(n-2*k)
A=np.array([[a*a+b,a],[a*b,b]])
B=pow(A,k)
print(int(B[0,l]))
0