結果

問題 No.492 IOI数列
ユーザー kk
提出日時 2021-03-14 02:58:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 104 ms / 1,000 ms
コード長 737 bytes
コンパイル時間 1,362 ms
コンパイル使用メモリ 86,676 KB
実行使用メモリ 76,468 KB
最終ジャッジ日時 2023-08-05 17:54:18
合計ジャッジ時間 4,128 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
71,160 KB
testcase_01 AC 104 ms
76,352 KB
testcase_02 AC 99 ms
76,368 KB
testcase_03 AC 93 ms
76,468 KB
testcase_04 AC 86 ms
76,400 KB
testcase_05 AC 82 ms
76,456 KB
testcase_06 AC 90 ms
76,440 KB
testcase_07 AC 88 ms
76,292 KB
testcase_08 AC 89 ms
76,300 KB
testcase_09 AC 88 ms
76,396 KB
testcase_10 AC 79 ms
71,112 KB
testcase_11 AC 75 ms
71,312 KB
testcase_12 AC 76 ms
71,200 KB
testcase_13 AC 75 ms
71,112 KB
testcase_14 AC 75 ms
71,380 KB
testcase_15 AC 73 ms
71,476 KB
testcase_16 AC 74 ms
71,248 KB
testcase_17 AC 77 ms
71,072 KB
testcase_18 AC 77 ms
71,308 KB
testcase_19 AC 78 ms
71,360 KB
testcase_20 AC 84 ms
75,668 KB
testcase_21 AC 86 ms
75,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

M1 = 1000000007
M2 = 101010101010101010101

A = [
  [0, 1, 0],
  [0, 100, 1],
  [0, 0, 1]
]

def multiply(x, y, m):
  z = [[0,0,0], [0,0,0], [0,0,0]]
  for i in range(3):
    for j in range(3):
      for k in range(3):
        z[i][j] += x[i][k] * y[k][j]
        z[i][j] %= m
  return z

def modpow(x, p, m):
  r = [[1,0,0],[0,1,0],[0,0,1]]
  base = x
  while p > 0:
    if p & 1 == 1:
      r = multiply(r, base, m)
    base = multiply(base, base, m)
    p = p >> 1
  return r

def main():
  n = int(input())
  x = modpow([[0,1,0],[0,100,1],[0,0,1]], n, M1)
  y = modpow([[0,1,0],[0,100,1],[0,0,1]], n, M2)
  r1 = (x[0][1] + x[0][2]) % M1
  r2 = (y[0][1] + y[0][2]) % M2
  print(r1)
  print(r2)

if __name__ == '__main__':
  main()
  
0