結果

問題 No.64 XORフィボナッチ数列
ユーザー toshiro_yanagitoshiro_yanagi
提出日時 2018-06-01 11:15:57
言語 Nim
(2.0.2)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 753 bytes
コンパイル時間 5,360 ms
コンパイル使用メモリ 68,812 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-12 21:16:09
合計ジャッジ時間 5,600 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import strutils, sequtils, math

proc tBin(i: int): string =
  var bf = i
  var w = ""
  while bf != 0:
    w = int(bf mod 2 != 0).repr & w
    bf = bf div 2
  result = w

proc xOR0(x0: string, y0: string): string =
  var x, y: string
  y = align(y0, max(x0.len, y0.len), '0')
  x = align(x0, max(x0.len, y0.len), '0')

  result = ""
  for i in 0 ..< x.len:
    if ($x[i]).parseInt + ($y[i]).parseInt == 1:
      result.add('1')
    else:
      result.add('0')

proc rpr(s: string): int =
  for i, v in s:
    if $v == $1:
      result += 2 ^ (s.high - i)


let ris = stdin.readLine.split.map(parseInt)
let (f0, f1, n) = (ris[0], ris[1], ris[2])
let f2 = xOR0(f0.tBin, f1.tBin).rpr

case n mod 3:
of 0: echo f0
of 1: echo f1
of 2: echo f2
else: discard
0