結果

問題 No.1073 無限すごろく
ユーザー roarisroaris
提出日時 2020-06-05 23:48:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 771 bytes
コンパイル時間 1,285 ms
コンパイル使用メモリ 86,384 KB
実行使用メモリ 76,172 KB
最終ジャッジ日時 2023-08-22 18:27:05
合計ジャッジ時間 5,444 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
70,756 KB
testcase_01 AC 74 ms
70,940 KB
testcase_02 AC 91 ms
75,800 KB
testcase_03 AC 74 ms
70,796 KB
testcase_04 AC 77 ms
71,076 KB
testcase_05 AC 80 ms
75,440 KB
testcase_06 AC 80 ms
75,324 KB
testcase_07 AC 78 ms
75,704 KB
testcase_08 AC 78 ms
75,504 KB
testcase_09 AC 78 ms
75,704 KB
testcase_10 AC 79 ms
75,596 KB
testcase_11 AC 78 ms
75,332 KB
testcase_12 AC 78 ms
75,392 KB
testcase_13 AC 79 ms
75,872 KB
testcase_14 AC 80 ms
75,772 KB
testcase_15 AC 80 ms
76,124 KB
testcase_16 AC 78 ms
75,972 KB
testcase_17 AC 78 ms
76,152 KB
testcase_18 AC 79 ms
76,036 KB
testcase_19 AC 80 ms
75,844 KB
testcase_20 AC 80 ms
75,956 KB
testcase_21 AC 81 ms
75,836 KB
testcase_22 AC 82 ms
75,964 KB
testcase_23 AC 83 ms
75,936 KB
testcase_24 AC 83 ms
76,052 KB
testcase_25 AC 83 ms
76,044 KB
testcase_26 AC 82 ms
75,852 KB
testcase_27 AC 81 ms
76,172 KB
testcase_28 AC 81 ms
76,100 KB
testcase_29 AC 82 ms
75,928 KB
testcase_30 AC 82 ms
75,872 KB
testcase_31 AC 81 ms
75,936 KB
testcase_32 AC 81 ms
76,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def mat_mul(A, B):
    C = [[0]*len(B[0]) for _ in range(len(A))]
    
    for i in range(len(A)):
        for j in range(len(B[0])):
            for k in range(len(A[0])):
                C[i][j] += A[i][k]*B[k][j]
                C[i][j] %= MOD
    
    return C

def mat_pow(A, n):
    res = [[0]*len(A) for _ in range(len(A))]
    
    for i in range(len(A)):
        res[i][i] = 1
    
    while n>0:
        if n&1:
            res = mat_mul(res, A)
        
        n >>= 1
        A = mat_mul(A, A)
    
    return res

N = int(input())
MOD = 10**9+7
x = [[1], [0], [0], [0], [0], [0]]
A = [[0]*6 for _ in range(6)]

for i in range(6):
    A[0][i] = pow(6, MOD-2, MOD)

for i in range(1, 6):
    A[i][i-1] = 1
    
res = mat_mul(mat_pow(A, N), x)
print(res[0][0])
0