結果

問題 No.64 XORフィボナッチ数列
ユーザー gogoteagogotea
提出日時 2015-04-29 19:41:13
言語 Go1.4
(1.4.2)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 905 bytes
コンパイル時間 324 ms
コンパイル使用メモリ 33,724 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-03 20:17:46
合計ジャッジ時間 983 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner(os.Stdin)
	F0, _ := sc.NextLong()
	F1, _ := sc.NextLong()
	N, _ := sc.NextLong()

	fmt.Println(solve(F0, F1, N))
}

func solve(f0, f1, n int64) int64 {
	switch n % 3 {
	case 0:
		return f0
	case 1:
		return f1
	default:
		f2 := f0 ^ f1
		return f2
	}
}

type Scanner struct {
	*bufio.Scanner
}

func NewScanner(r io.Reader) *Scanner {
	return &Scanner{
		bufio.NewScanner(r),
	}
}

func (s *Scanner) Next() (string, error) {
	s.Scanner.Split(bufio.ScanWords)
	return s.nextToken()
}

func (s *Scanner) nextToken() (string, error) {
	sc := s.Scanner
	if sc.Scan() {
		return sc.Text(), nil
	}
	if sc.Err() != nil {
		return "", sc.Err()
	}
	return "", io.EOF
}

func (s *Scanner) NextLong() (int64, error) {
	token, err := s.Next()
	if err != nil {
		return 0, err
	}
	return strconv.ParseInt(token, 10, 64)
}
0