結果

問題 No.657 テトラナッチ数列 Easy
ユーザー むらため
提出日時 2019-01-17 20:14:31
言語 Nim
(2.2.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 669 bytes
コンパイル時間 2,373 ms
コンパイル使用メモリ 60,900 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-01 10:10:43
合計ジャッジ時間 3,148 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>" .}
proc scan(): int =
  while true:
    var k = getchar_unlocked()
    if k < '0' or k > '9': break
    else: result = 10 * result + k.ord - '0'.ord
template times*(n:int,body) = (for _ in 0..<n: body)

const ts = (proc() : seq[int]=
  var (a,b,c,d) = (0,0,0,1)
  var n = 0
  var ts = @[0,0,0,0,1]
  while true:
    (a,b,c,d) = (b,c,d,(a+b+c+d) mod 17)
    if a == 0 and b == 0 and c == 0 and d == 1 : break
    n += 1
    ts &= d
  return ts
)()

proc getTet(n:int):int =
  if n < ts.len  : return ts[n]
  return ts[4 + (n-4) mod (ts.len - 4)]

let q = scan()
q.times: echo scan().getTet()
0