結果

問題 No.891 隣接3項間の漸化式
ユーザー ikdikd
提出日時 2019-09-20 22:55:39
言語 Nim
(2.0.2)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 799 bytes
コンパイル時間 5,447 ms
コンパイル使用メモリ 68,272 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-12 20:48:48
合計ジャッジ時間 7,020 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,356 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,356 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 1 ms
4,352 KB
testcase_14 AC 1 ms
4,352 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 2 ms
4,352 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 1 ms
4,352 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 2 ms
4,352 KB
testcase_21 AC 2 ms
4,352 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,352 KB
testcase_25 AC 1 ms
4,352 KB
testcase_26 AC 2 ms
4,352 KB
testcase_27 AC 2 ms
4,352 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,352 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 1 ms
4,356 KB
testcase_32 AC 1 ms
4,348 KB
testcase_33 AC 2 ms
4,352 KB
testcase_34 AC 2 ms
4,356 KB
testcase_35 AC 2 ms
4,356 KB
testcase_36 AC 1 ms
4,356 KB
testcase_37 AC 1 ms
4,352 KB
testcase_38 AC 1 ms
4,348 KB
testcase_39 AC 2 ms
4,348 KB
testcase_40 AC 2 ms
4,352 KB
testcase_41 AC 2 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import strutils, sequtils

const mo: int64 = 1000000000 + 7
proc add(a: var int64, b: int64) =
  a = (a + b) mod mo

proc main() =
  var a, b, n: int
  (a, b, n) = stdin.readLine.strip.split.map(parseInt)

  if n <= 1:
    echo n
    return
  var mat = newSeqWith(32, newSeqwith(2, newSeq[int64](2)))
  mat[0][0][0] = a
  mat[0][0][1] = b
  mat[0][1][0] = 1
  mat[0][1][1] = 0
  for i in 1..<32:
    for y in 0..<2:
      for x in 0..<2:
        for t in 0..<2:
          add(mat[i][y][x], mat[i - 1][y][t] * mat[i - 1][t][x] mod mo)
  var v = newSeq[int64](2)
  v[0] = 1
  v[1] = 0
  for i in 0..<32:
    if ((n - 1) and (1 shl i)) > 0:
      var u = newSeq[int64](2)
      for j in 0..<2:
        for t in 0..<2:
          add(u[j], mat[i][j][t] * v[t] mod mo)
      swap(u, v)
  echo v[0]
main()
0