結果

問題 No.1073 無限すごろく
ユーザー H3PO4H3PO4
提出日時 2023-06-17 20:20:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 503 bytes
コンパイル時間 239 ms
コンパイル使用メモリ 10,892 KB
実行使用メモリ 29,740 KB
最終ジャッジ日時 2023-09-07 16:19:39
合計ジャッジ時間 7,068 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
29,632 KB
testcase_01 AC 133 ms
29,636 KB
testcase_02 AC 132 ms
29,604 KB
testcase_03 AC 130 ms
29,576 KB
testcase_04 AC 132 ms
29,644 KB
testcase_05 AC 131 ms
29,504 KB
testcase_06 AC 129 ms
29,684 KB
testcase_07 AC 130 ms
29,636 KB
testcase_08 AC 130 ms
29,468 KB
testcase_09 AC 130 ms
29,560 KB
testcase_10 AC 129 ms
29,596 KB
testcase_11 AC 133 ms
29,620 KB
testcase_12 AC 132 ms
29,604 KB
testcase_13 AC 131 ms
29,620 KB
testcase_14 AC 137 ms
29,600 KB
testcase_15 AC 133 ms
29,724 KB
testcase_16 AC 133 ms
29,660 KB
testcase_17 AC 133 ms
29,572 KB
testcase_18 AC 133 ms
29,692 KB
testcase_19 AC 137 ms
29,628 KB
testcase_20 AC 132 ms
29,672 KB
testcase_21 AC 131 ms
29,616 KB
testcase_22 AC 131 ms
29,696 KB
testcase_23 AC 129 ms
29,708 KB
testcase_24 AC 131 ms
29,536 KB
testcase_25 AC 131 ms
29,676 KB
testcase_26 AC 131 ms
29,648 KB
testcase_27 AC 135 ms
29,704 KB
testcase_28 AC 132 ms
29,576 KB
testcase_29 AC 132 ms
29,700 KB
testcase_30 AC 131 ms
29,716 KB
testcase_31 AC 139 ms
29,736 KB
testcase_32 AC 133 ms
29,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np

N = int(input())

MOD = 10 ** 9 + 7
modinv = lambda a, mod=MOD: pow(a, mod - 2, mod)


def pow_matrix_mod(x, n, mod=MOD):
    x = x.astype(object)
    if not n:
        return np.eye(len(x), dtype=object)
    if n % 2 == 0:
        return pow_matrix_mod(x @ x % mod, n // 2) % mod
    else:
        return x @ pow_matrix_mod(x @ x % mod, (n - 1) // 2) % mod


A = np.zeros((6, 6), dtype=int)
A[0] = modinv(6)
for i in range(5):
    A[i + 1, i] = 1

print(pow_matrix_mod(A, N)[0, 0])
0