結果

問題 No.492 IOI数列
ユーザー kk
提出日時 2021-03-14 02:58:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 57 ms / 1,000 ms
コード長 737 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 82,116 KB
実行使用メモリ 66,176 KB
最終ジャッジ日時 2024-04-23 14:41:53
合計ジャッジ時間 2,276 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
51,840 KB
testcase_01 AC 54 ms
64,128 KB
testcase_02 AC 57 ms
66,176 KB
testcase_03 AC 55 ms
64,976 KB
testcase_04 AC 48 ms
61,696 KB
testcase_05 AC 47 ms
61,696 KB
testcase_06 AC 57 ms
64,384 KB
testcase_07 AC 54 ms
64,256 KB
testcase_08 AC 54 ms
64,896 KB
testcase_09 AC 55 ms
64,128 KB
testcase_10 AC 38 ms
52,224 KB
testcase_11 AC 39 ms
52,224 KB
testcase_12 AC 38 ms
52,608 KB
testcase_13 AC 39 ms
52,096 KB
testcase_14 AC 38 ms
52,336 KB
testcase_15 AC 39 ms
52,096 KB
testcase_16 AC 40 ms
52,480 KB
testcase_17 AC 38 ms
51,968 KB
testcase_18 AC 40 ms
52,352 KB
testcase_19 AC 40 ms
52,608 KB
testcase_20 AC 44 ms
59,008 KB
testcase_21 AC 46 ms
60,416 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