結果

問題 No.891 隣接3項間の漸化式
ユーザー Konton7Konton7
提出日時 2019-09-28 13:06:55
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 617 bytes
コンパイル時間 141 ms
コンパイル使用メモリ 82,672 KB
実行使用メモリ 54,820 KB
最終ジャッジ日時 2024-04-09 23:38:19
合計ジャッジ時間 2,931 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,172 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 36 ms
52,872 KB
testcase_14 WA -
testcase_15 AC 36 ms
52,992 KB
testcase_16 AC 36 ms
53,008 KB
testcase_17 AC 36 ms
52,588 KB
testcase_18 WA -
testcase_19 AC 38 ms
52,480 KB
testcase_20 AC 36 ms
53,352 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 36 ms
53,260 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 36 ms
53,428 KB
testcase_38 WA -
testcase_39 AC 37 ms
52,660 KB
testcase_40 WA -
testcase_41 AC 38 ms
53,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

a, b, n = [ int(v) for v in input().split() ]

path_mat = [ [a, b], [1, 0] ]

mod = 10**9+7

def mat_mul(inmat1,inmat2,m):
    outmat = [ [ 0 for j in range(m) ] for i in range(m) ]

    for i in range(m):
        for j in range(m):
            for g in range(m):
                outmat[i][j] += inmat1[i][g] * inmat2[g][j]
            outmat[i][j] %= mod
    return outmat


ans_mat = [ [ 1 if i == j else 0 for j in range(2) ] for i in range(2) ]

while n != 0:
    if n % 2 == 1:
        ans_mat = mat_mul(ans_mat,path_mat,2)
    n = n // 2
    path_mat = mat_mul(path_mat,path_mat,2)
    
print(ans_mat[0][1]%mod)
0