結果

問題 No.1073 無限すごろく
ユーザー realDivineJKrealDivineJK
提出日時 2020-06-05 22:10:43
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 1,343 bytes
コンパイル時間 167 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-05-09 21:32:13
合計ジャッジ時間 2,201 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
10,880 KB
testcase_01 AC 26 ms
10,880 KB
testcase_02 AC 27 ms
10,752 KB
testcase_03 AC 25 ms
10,880 KB
testcase_04 AC 25 ms
10,752 KB
testcase_05 AC 26 ms
10,752 KB
testcase_06 AC 25 ms
10,880 KB
testcase_07 AC 25 ms
10,752 KB
testcase_08 AC 27 ms
10,752 KB
testcase_09 AC 26 ms
10,880 KB
testcase_10 AC 28 ms
10,752 KB
testcase_11 AC 27 ms
10,880 KB
testcase_12 AC 27 ms
10,880 KB
testcase_13 AC 26 ms
10,752 KB
testcase_14 AC 26 ms
10,880 KB
testcase_15 AC 26 ms
10,752 KB
testcase_16 AC 26 ms
10,752 KB
testcase_17 AC 27 ms
10,752 KB
testcase_18 AC 27 ms
10,880 KB
testcase_19 AC 26 ms
10,880 KB
testcase_20 AC 27 ms
10,880 KB
testcase_21 AC 27 ms
10,752 KB
testcase_22 AC 27 ms
10,880 KB
testcase_23 AC 29 ms
10,752 KB
testcase_24 AC 29 ms
10,880 KB
testcase_25 AC 30 ms
10,752 KB
testcase_26 AC 29 ms
10,880 KB
testcase_27 AC 28 ms
10,752 KB
testcase_28 AC 30 ms
10,752 KB
testcase_29 AC 30 ms
10,880 KB
testcase_30 AC 29 ms
10,880 KB
testcase_31 AC 30 ms
10,752 KB
testcase_32 AC 30 ms
10,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = int(1e9) + 7
vec = [1, 1, 7, 49, 343, 2401]
for i in range(6):
    vec[i] *= 6**(5-i)
def doubling(n, m):
    y = 1
    base = n
    tmp = m
    while tmp != 0:
        if tmp % 2 == 1:
            y *= base
            y %= mod
        base *= base
        base %= mod
        tmp //= 2
    return y
def inved(a):
    x, y, u, v, k, l = 1, 0, 0, 1, a, mod
    while l != 0:
        x, y, u, v = u, v, x - u * (k // l), y - v * (k // l)
        k, l = l, k % l
    return x % mod

def matprod(m1, m2, n, l, m):
    y = [[0 for _ in range(m)] for __ in range(n)]
    for i in range(n):
        for j in range(m):
            for k in range(l):
                y[i][j] += m1[i][k] * m2[k][j] % mod
                y[i][j] %= mod
    return y
    
def matpow(m1, n, m):
    y = [[i==j for j in range(n)] for i in range(n)]
    bas = [[m1[i][j] for j in range(n)] for i in range(n)]
    tmp = m
    while tmp != 0:
        if tmp % 2 == 1:
            y = matprod(y, bas, n, n, n)[:][:]
        bas = matprod(bas, bas, n, n, n)[:][:]
        tmp //= 2
    return y
    
N = int(input())
bas = [[0 for j in range(6)] for i in range(6)]
for i in range(5):
    bas[i][i+1] = 6
    bas[-1][i] = 1
bas[-1][-1] = 1
mat = matpow(bas, 6, N)
S = 0
for i in range(6):
    S += vec[i] * mat[0][i] % mod
    S %= mod
print(S*inved(doubling(6, N+5))%mod)
0