結果

問題 No.1073 無限すごろく
ユーザー qumazakiqumazaki
提出日時 2020-06-06 03:22:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 108 ms / 2,000 ms
コード長 795 bytes
コンパイル時間 589 ms
コンパイル使用メモリ 86,900 KB
実行使用メモリ 78,108 KB
最終ジャッジ日時 2023-08-23 08:29:36
合計ジャッジ時間 6,154 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 102 ms
77,544 KB
testcase_01 AC 103 ms
77,712 KB
testcase_02 AC 108 ms
77,716 KB
testcase_03 AC 103 ms
77,640 KB
testcase_04 AC 104 ms
78,108 KB
testcase_05 AC 105 ms
77,812 KB
testcase_06 AC 105 ms
77,732 KB
testcase_07 AC 102 ms
77,848 KB
testcase_08 AC 102 ms
77,992 KB
testcase_09 AC 102 ms
77,708 KB
testcase_10 AC 104 ms
77,648 KB
testcase_11 AC 104 ms
77,652 KB
testcase_12 AC 103 ms
77,712 KB
testcase_13 AC 104 ms
77,704 KB
testcase_14 AC 105 ms
77,876 KB
testcase_15 AC 106 ms
77,716 KB
testcase_16 AC 104 ms
77,856 KB
testcase_17 AC 107 ms
77,796 KB
testcase_18 AC 104 ms
77,872 KB
testcase_19 AC 107 ms
77,864 KB
testcase_20 AC 105 ms
77,708 KB
testcase_21 AC 105 ms
77,744 KB
testcase_22 AC 106 ms
77,752 KB
testcase_23 AC 106 ms
77,820 KB
testcase_24 AC 106 ms
77,852 KB
testcase_25 AC 107 ms
77,920 KB
testcase_26 AC 107 ms
78,080 KB
testcase_27 AC 107 ms
78,048 KB
testcase_28 AC 107 ms
77,804 KB
testcase_29 AC 107 ms
77,724 KB
testcase_30 AC 107 ms
77,696 KB
testcase_31 AC 108 ms
77,888 KB
testcase_32 AC 106 ms
77,836 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