結果

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

テストケース

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

ソースコード

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 {
	var fn int64

	if n == 0 {
		return f0
	} else if n == 1 {
		return f1
	}

	var i int64 = 2
	for {
		fn = f0 ^ f1
		if i >= n {
			break
		}
		i++
		f0 = f1
		f1 = fn
	}
	return fn
}

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