結果

問題 No.1073 無限すごろく
ユーザー qumazakiqumazaki
提出日時 2020-06-06 03:22:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 795 bytes
コンパイル時間 253 ms
コンパイル使用メモリ 82,556 KB
実行使用メモリ 71,060 KB
最終ジャッジ日時 2024-06-01 06:10:41
合計ジャッジ時間 3,532 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
68,520 KB
testcase_01 AC 65 ms
68,768 KB
testcase_02 AC 66 ms
69,132 KB
testcase_03 AC 64 ms
68,700 KB
testcase_04 AC 63 ms
67,536 KB
testcase_05 AC 62 ms
68,656 KB
testcase_06 AC 62 ms
68,140 KB
testcase_07 AC 64 ms
67,892 KB
testcase_08 AC 64 ms
67,808 KB
testcase_09 AC 62 ms
67,812 KB
testcase_10 AC 63 ms
67,776 KB
testcase_11 AC 64 ms
67,656 KB
testcase_12 AC 64 ms
68,140 KB
testcase_13 AC 65 ms
69,436 KB
testcase_14 AC 65 ms
68,652 KB
testcase_15 AC 67 ms
68,456 KB
testcase_16 AC 65 ms
68,716 KB
testcase_17 AC 67 ms
71,060 KB
testcase_18 AC 67 ms
70,156 KB
testcase_19 AC 67 ms
68,568 KB
testcase_20 AC 70 ms
69,772 KB
testcase_21 AC 66 ms
69,080 KB
testcase_22 AC 66 ms
69,584 KB
testcase_23 AC 67 ms
69,416 KB
testcase_24 AC 67 ms
69,716 KB
testcase_25 AC 66 ms
70,092 KB
testcase_26 AC 67 ms
69,460 KB
testcase_27 AC 66 ms
69,536 KB
testcase_28 AC 70 ms
70,040 KB
testcase_29 AC 67 ms
69,852 KB
testcase_30 AC 67 ms
69,712 KB
testcase_31 AC 67 ms
69,984 KB
testcase_32 AC 67 ms
70,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import copy

n = int(input())
mod = 10**9 + 7

def mat_power(a,b):
    # aもbもm*m列の行列とする。
    m = 6
    res = [[0] *m for _ in range(m)]
    for i in range(m):
        for j in range(m):
            for k in range(m):
                res[i][j] += a[i][k] * b[k][j]
            res[i][j] %= mod

    return res

# x0 = [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(5):
    a[i+1][i] = 1

a_exp = []
a_exp.append(a)
i = 1
while(2**i < 10**18):
    ai = mat_power(a_exp[-1],a_exp[-1])
    a_exp.append(copy.deepcopy(ai))
    i += 1

a_n = [[0]*6 for _ in range(6)]
for i in range(6):
    a_n[i][i] = 1

i = 0
while(n>0):
    if(n%2==1):
        a_n = mat_power(a_n,a_exp[i])
    i += 1
    n //= 2

print(a_n[0][0])
0