結果

問題 No.1073 無限すごろく
ユーザー 👑 KazunKazun
提出日時 2020-06-05 23:09:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 751 bytes
コンパイル時間 300 ms
コンパイル使用メモリ 87,196 KB
実行使用メモリ 76,848 KB
最終ジャッジ日時 2023-08-22 17:22:52
合計ジャッジ時間 4,055 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,356 KB
testcase_01 AC 69 ms
71,180 KB
testcase_02 AC 104 ms
76,472 KB
testcase_03 AC 67 ms
71,292 KB
testcase_04 AC 74 ms
71,484 KB
testcase_05 AC 69 ms
71,240 KB
testcase_06 AC 69 ms
71,356 KB
testcase_07 AC 69 ms
71,356 KB
testcase_08 AC 72 ms
75,692 KB
testcase_09 AC 72 ms
75,424 KB
testcase_10 AC 72 ms
75,820 KB
testcase_11 AC 74 ms
75,860 KB
testcase_12 AC 74 ms
75,568 KB
testcase_13 AC 75 ms
76,660 KB
testcase_14 AC 77 ms
76,452 KB
testcase_15 AC 78 ms
76,672 KB
testcase_16 AC 79 ms
76,580 KB
testcase_17 AC 79 ms
76,352 KB
testcase_18 AC 79 ms
76,760 KB
testcase_19 AC 79 ms
76,504 KB
testcase_20 AC 79 ms
76,352 KB
testcase_21 AC 77 ms
76,672 KB
testcase_22 AC 79 ms
76,500 KB
testcase_23 AC 81 ms
76,704 KB
testcase_24 AC 82 ms
76,248 KB
testcase_25 AC 83 ms
76,544 KB
testcase_26 AC 81 ms
76,848 KB
testcase_27 AC 78 ms
76,356 KB
testcase_28 AC 82 ms
76,832 KB
testcase_29 AC 83 ms
76,516 KB
testcase_30 AC 82 ms
76,584 KB
testcase_31 AC 83 ms
76,636 KB
testcase_32 AC 82 ms
76,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from math import log
def m(A,B,Y):
    C=[]
    for i in range(6):
        D=[]
        for j in range(6):
            S=0
            for k in range(6):
                S=(S+A[i][k]*B[k][j])%Y

            D.append(S)
        C.append(D)
    return C

Y=10**9+7
a=166666668

N=int(input())

if N<=6:
    print((7**(N-1)*a**N)%Y)
    sys.exit()

P=[[a,a,a,a,a,a],[1,0,0,0,0,0],[0,1,0,0,0,0],[0,0,1,0,0,0],[0,0,0,1,0,0],[0,0,0,0,1,0]]
Q=[P]

for _ in range(int(log(N,2))+1):
    R=Q[-1]
    Q.append(m(R,R,Y))

M=N-6
Z=[[1*(i==j) for j in range(6)] for i in range(6)]
for i in range(int(log(N,2))+1):
    if M%2==1:
        Z=m(Z,Q[i],Y)
    M=M>>1

W=0
L=a
for j in range(6):
    W=(W+Z[0][5-j]*L)%Y
    L=(L*a*7)%Y

print(W)
        
    
0