結果

問題 No.492 IOI数列
ユーザー 0w10w1
提出日時 2017-04-10 19:18:33
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 81 ms / 1,000 ms
コード長 815 bytes
コンパイル時間 267 ms
コンパイル使用メモリ 86,928 KB
実行使用メモリ 76,332 KB
最終ジャッジ日時 2023-09-25 06:50:48
合計ジャッジ時間 3,198 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,140 KB
testcase_01 AC 77 ms
76,180 KB
testcase_02 AC 81 ms
76,332 KB
testcase_03 AC 75 ms
76,248 KB
testcase_04 AC 70 ms
71,428 KB
testcase_05 AC 70 ms
71,500 KB
testcase_06 AC 76 ms
75,792 KB
testcase_07 AC 78 ms
76,160 KB
testcase_08 AC 77 ms
76,092 KB
testcase_09 AC 76 ms
76,036 KB
testcase_10 AC 68 ms
71,436 KB
testcase_11 AC 69 ms
71,268 KB
testcase_12 AC 69 ms
71,504 KB
testcase_13 AC 69 ms
71,500 KB
testcase_14 AC 69 ms
71,196 KB
testcase_15 AC 68 ms
71,124 KB
testcase_16 AC 68 ms
71,288 KB
testcase_17 AC 69 ms
71,200 KB
testcase_18 AC 69 ms
71,504 KB
testcase_19 AC 69 ms
71,544 KB
testcase_20 AC 71 ms
71,128 KB
testcase_21 AC 72 ms
71,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD7 = int( 1e9 ) + 7
MOD1 = 101010101010101010101

N = int( input() )

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

def mat_mul( a, b, mod ):
  c = [ [ 0 for i in range( len( b[ 0 ] ) ) ] for j in range( len( a ) ) ]
  for i in range( len( a ) ):
    for k in range( len( a[ 0 ] ) ):
      for j in range( len( b[ 0 ] ) ):
        c[ i ][ j ] += a[ i ][ k ] * b[ k ][ j ]
        c[ i ][ j ] %= mod
  return c

def mat_pow( a, n, mod ):
  res = [ [ 0 for i in range( len( a ) ) ] for j in range( len( a ) ) ]
  for i in range( len( res ) ):
    res[ i ][ i ] = 1
  while n:
    if n & 1:
      res = mat_mul( res, a, mod )
    n >>= 1
    a = mat_mul( a, a, mod )
  return res

print( mat_mul( mat_pow( A, N - 1, MOD7 ), x, MOD7 )[ 0 ][ 0 ] )
print( mat_mul( mat_pow( A, N - 1, MOD1 ), x, MOD1 )[ 0 ][ 0 ] )
0