結果

問題 No.1073 無限すごろく
ユーザー SalmonizeSalmonize
提出日時 2020-06-05 21:45:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 1,300 bytes
コンパイル時間 197 ms
コンパイル使用メモリ 10,852 KB
実行使用メモリ 8,120 KB
最終ジャッジ日時 2023-08-22 14:54:30
合計ジャッジ時間 2,045 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,076 KB
testcase_01 AC 16 ms
8,116 KB
testcase_02 AC 16 ms
7,984 KB
testcase_03 AC 16 ms
8,040 KB
testcase_04 AC 15 ms
8,048 KB
testcase_05 AC 16 ms
8,120 KB
testcase_06 AC 16 ms
8,104 KB
testcase_07 AC 16 ms
8,076 KB
testcase_08 AC 16 ms
8,024 KB
testcase_09 AC 16 ms
8,012 KB
testcase_10 AC 16 ms
8,048 KB
testcase_11 AC 16 ms
7,984 KB
testcase_12 AC 16 ms
8,076 KB
testcase_13 AC 16 ms
7,984 KB
testcase_14 AC 16 ms
8,016 KB
testcase_15 AC 16 ms
8,080 KB
testcase_16 AC 16 ms
8,048 KB
testcase_17 AC 16 ms
8,100 KB
testcase_18 AC 16 ms
8,052 KB
testcase_19 AC 15 ms
8,048 KB
testcase_20 AC 16 ms
8,048 KB
testcase_21 AC 16 ms
8,076 KB
testcase_22 AC 16 ms
8,052 KB
testcase_23 AC 17 ms
8,016 KB
testcase_24 AC 16 ms
8,024 KB
testcase_25 AC 16 ms
7,984 KB
testcase_26 AC 17 ms
8,024 KB
testcase_27 AC 16 ms
8,088 KB
testcase_28 AC 16 ms
8,120 KB
testcase_29 AC 17 ms
8,080 KB
testcase_30 AC 17 ms
7,996 KB
testcase_31 AC 16 ms
8,044 KB
testcase_32 AC 17 ms
8,004 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

readline = sys.stdin.readline

ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))

def Kitamasa(C, X, k, e0=0, e1=1, mod=10**9+7):
	'''
	0-indexed
	calc X[k]
	'''
	n = len(X)

	def _plus1(g):
	    ret = [(g[i-1] + g[-1] * C[i]) % mod for i in range(n)]
	    ret[0] = g[-1] * C[0] % mod
	    return ret

	def _mult2(g):
	    ret = [e0]*(2 * n - 1)
	    for i in range(n):
		    for j in range(n):
		        ret[i + j] = (ret[i + j] + g[i] * g[j]) % mod
	    for i in range(2*n-2, n-1, -1):
		    for j in range(n):
		        ret[i + j - n] = (ret[i + j - n] + ret[i] * C[j]) % mod
	    return ret[:n]

	g = [e0]*n
	g[0] = e1
	t = k.bit_length()
	for i in range(t-1, -1, -1):
		g = _mult2(g)
		if k & (1<<i):
			g = _plus1(g)

	ans = e0
	for i in range(n):
		ans = (ans + g[i] * X[i]) % mod

	return ans

def modinv(x, mod):
    a, b = x, mod
    u, v = 1, 0
    while b:
        t = a // b
        a -= t * b; a, b = b, a
        u -= t * v; u, v = v, u
    return u % mod

def solve():
    n = ni()
    mod = 10**9 + 7
    inv6 = modinv(6, mod)
    X = [1, 166666668, 194444446, 893518525, 209104940, 577289099]
    C = [inv6]*6
    print(Kitamasa(C, X, n))
    return

solve()
0