結果

問題 No.658 テトラナッチ数列 Hard
ユーザー むらためむらため
提出日時 2019-01-17 20:29:37
言語 Nim
(2.0.2)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,225 bytes
コンパイル時間 2,147 ms
コンパイル使用メモリ 66,184 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 02:05:54
合計ジャッジ時間 2,984 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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)
proc putchar_unlocked(c:char){.header: "<stdio.h>" .}
proc printInt(a:int,skipLeavingZeros:bool = false) =
  if a == 0:
    putchar_unlocked('0')
    return
  var n = a
  var rev = a
  var cnt = 0
  while rev mod 10 == 0:
    cnt += 1
    rev = rev div 10
  rev = 0
  while n != 0:
    rev = (rev shl 3) + (rev shl 1) + n mod 10
    n = n div 10
  while rev != 0:
    putchar_unlocked((rev mod 10 + '0'.ord).chr)
    rev = rev div 10
  if not skipLeavingZeros:
    while cnt != 0:
      putchar_unlocked('0')
      cnt -= 1


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:
  printInt(scan().getTet())
  putchar_unlocked('\n')
0