結果

問題 No.657 テトラナッチ数列 Easy
ユーザー むらためむらため
提出日時 2019-01-17 20:17:06
言語 Nim
(2.0.2)
結果
WA  
実行時間 -
コード長 1,076 bytes
コンパイル時間 2,627 ms
コンパイル使用メモリ 66,332 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-14 02:05:21
合計ジャッジ時間 2,838 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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) =
  if a == 0:
    putchar_unlocked('0')
    return
  var n = a
  var rev = a
  while rev mod 10 == 0: 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


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