結果

問題 No.891 隣接3項間の漸化式
ユーザー titiatitia
提出日時 2019-09-20 22:05:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 714 bytes
コンパイル時間 124 ms
コンパイル使用メモリ 11,008 KB
実行使用メモリ 8,352 KB
最終ジャッジ日時 2023-10-12 19:17:03
合計ジャッジ時間 2,641 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,212 KB
testcase_01 AC 17 ms
8,008 KB
testcase_02 AC 17 ms
7,964 KB
testcase_03 AC 17 ms
8,120 KB
testcase_04 AC 17 ms
8,164 KB
testcase_05 AC 17 ms
8,080 KB
testcase_06 AC 17 ms
7,964 KB
testcase_07 AC 17 ms
8,004 KB
testcase_08 AC 17 ms
8,016 KB
testcase_09 AC 17 ms
8,124 KB
testcase_10 AC 17 ms
8,068 KB
testcase_11 AC 16 ms
7,960 KB
testcase_12 AC 16 ms
8,072 KB
testcase_13 AC 16 ms
8,352 KB
testcase_14 AC 16 ms
8,208 KB
testcase_15 AC 17 ms
8,260 KB
testcase_16 AC 17 ms
7,992 KB
testcase_17 AC 17 ms
8,156 KB
testcase_18 AC 17 ms
8,016 KB
testcase_19 AC 17 ms
7,900 KB
testcase_20 AC 16 ms
8,168 KB
testcase_21 AC 16 ms
8,020 KB
testcase_22 AC 16 ms
8,132 KB
testcase_23 AC 17 ms
7,964 KB
testcase_24 AC 17 ms
8,036 KB
testcase_25 AC 17 ms
8,092 KB
testcase_26 AC 16 ms
7,972 KB
testcase_27 AC 16 ms
7,972 KB
testcase_28 AC 17 ms
8,032 KB
testcase_29 AC 17 ms
8,068 KB
testcase_30 AC 16 ms
8,012 KB
testcase_31 AC 17 ms
7,912 KB
testcase_32 AC 17 ms
8,044 KB
testcase_33 AC 16 ms
8,020 KB
testcase_34 AC 17 ms
8,132 KB
testcase_35 AC 16 ms
8,000 KB
testcase_36 AC 17 ms
8,016 KB
testcase_37 AC 17 ms
8,068 KB
testcase_38 AC 16 ms
7,992 KB
testcase_39 AC 17 ms
8,148 KB
testcase_40 AC 17 ms
7,960 KB
testcase_41 AC 17 ms
8,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

a,b,n=map(int,input().split())
mod=10**9+7

def prod(A,B,k,l,m):# A:k*l,B:l*m
    C=[[None for i in range(m)] for j in range(k)]

    for i in range(k):
        for j in range(m):
            ANS=0
            for pl in range(l):
                ANS=(ANS+A[i][pl]*B[pl][j])%mod

            C[i][j]=ANS

    return C

def plus(A,B,k,l):# a,B:k*l
    C=[[None for i in range(l)] for j in range(k)]

    for i in range(k):
        for j in range(l):
            C[i][j]=(A[i][j]+B[i][j])%mod

    return C

X=[[0,1]]
A=[[0,b],[1,a]]

POWA=[A]

for i in range(60):
    POWA.append(prod(POWA[-1],POWA[-1],2,2,2))


while n:
    X=prod(X,POWA[n.bit_length()-1],1,2,2)
    n-=1<<(n.bit_length()-1)

print(X[0][0])

    
0