結果

問題 No.891 隣接3項間の漸化式
ユーザー chanpukuchanpuku
提出日時 2019-11-25 23:32:33
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 518 ms / 2,000 ms
コード長 711 bytes
コンパイル時間 101 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 85,408 KB
最終ジャッジ日時 2024-04-23 01:07:00
合計ジャッジ時間 23,617 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 518 ms
43,980 KB
testcase_01 AC 460 ms
43,984 KB
testcase_02 AC 460 ms
44,376 KB
testcase_03 AC 471 ms
43,980 KB
testcase_04 AC 465 ms
43,984 KB
testcase_05 AC 451 ms
43,980 KB
testcase_06 AC 453 ms
44,244 KB
testcase_07 AC 454 ms
44,244 KB
testcase_08 AC 455 ms
44,392 KB
testcase_09 AC 456 ms
44,120 KB
testcase_10 AC 459 ms
44,612 KB
testcase_11 AC 444 ms
44,112 KB
testcase_12 AC 449 ms
44,236 KB
testcase_13 AC 457 ms
43,980 KB
testcase_14 AC 450 ms
44,240 KB
testcase_15 AC 449 ms
44,492 KB
testcase_16 AC 443 ms
44,240 KB
testcase_17 AC 451 ms
44,240 KB
testcase_18 AC 457 ms
44,360 KB
testcase_19 AC 452 ms
44,244 KB
testcase_20 AC 445 ms
44,236 KB
testcase_21 AC 452 ms
44,244 KB
testcase_22 AC 451 ms
44,620 KB
testcase_23 AC 463 ms
44,488 KB
testcase_24 AC 453 ms
44,244 KB
testcase_25 AC 461 ms
44,236 KB
testcase_26 AC 470 ms
44,236 KB
testcase_27 AC 509 ms
44,236 KB
testcase_28 AC 464 ms
44,368 KB
testcase_29 AC 475 ms
44,112 KB
testcase_30 AC 454 ms
43,984 KB
testcase_31 AC 453 ms
43,976 KB
testcase_32 AC 464 ms
44,396 KB
testcase_33 AC 453 ms
43,976 KB
testcase_34 AC 450 ms
44,236 KB
testcase_35 AC 465 ms
44,364 KB
testcase_36 AC 452 ms
43,980 KB
testcase_37 AC 459 ms
44,244 KB
testcase_38 AC 457 ms
44,236 KB
testcase_39 AC 453 ms
43,988 KB
testcase_40 AC 454 ms
43,976 KB
testcase_41 AC 455 ms
85,408 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