結果

問題 No.1073 無限すごろく
ユーザー realDivineJKrealDivineJK
提出日時 2020-06-05 22:10:43
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 1,343 bytes
コンパイル時間 138 ms
コンパイル使用メモリ 11,192 KB
実行使用メモリ 8,520 KB
最終ジャッジ日時 2023-08-22 15:48:14
合計ジャッジ時間 2,128 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,440 KB
testcase_01 AC 17 ms
8,420 KB
testcase_02 AC 18 ms
8,440 KB
testcase_03 AC 17 ms
8,408 KB
testcase_04 AC 17 ms
8,344 KB
testcase_05 AC 17 ms
8,480 KB
testcase_06 AC 17 ms
8,520 KB
testcase_07 AC 17 ms
8,520 KB
testcase_08 AC 17 ms
8,480 KB
testcase_09 AC 17 ms
8,344 KB
testcase_10 AC 17 ms
8,368 KB
testcase_11 AC 17 ms
8,372 KB
testcase_12 AC 16 ms
8,400 KB
testcase_13 AC 19 ms
8,500 KB
testcase_14 AC 18 ms
8,476 KB
testcase_15 AC 19 ms
8,460 KB
testcase_16 AC 19 ms
8,364 KB
testcase_17 AC 18 ms
8,496 KB
testcase_18 AC 19 ms
8,504 KB
testcase_19 AC 18 ms
8,468 KB
testcase_20 AC 19 ms
8,300 KB
testcase_21 AC 18 ms
8,420 KB
testcase_22 AC 18 ms
8,464 KB
testcase_23 AC 21 ms
8,368 KB
testcase_24 AC 20 ms
8,344 KB
testcase_25 AC 21 ms
8,440 KB
testcase_26 AC 21 ms
8,348 KB
testcase_27 AC 21 ms
8,508 KB
testcase_28 AC 23 ms
8,500 KB
testcase_29 AC 23 ms
8,440 KB
testcase_30 AC 23 ms
8,412 KB
testcase_31 AC 22 ms
8,508 KB
testcase_32 AC 22 ms
8,368 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