結果

問題 No.534 フィボナッチフィボナッチ数
ユーザー fmhrfmhr
提出日時 2017-06-23 22:53:30
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 795 bytes
コンパイル時間 12,246 ms
コンパイル使用メモリ 226,056 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-14 06:04:41
合計ジャッジ時間 13,596 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 2 ms
6,816 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 1 ms
6,944 KB
testcase_18 AC 1 ms
6,944 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
	"log"
)

type int uint

// yukicoder 526
// 最小二乗法
var M int

func main() {
	log.SetFlags(log.Lshortfile)
	M = 1000000007
	var N int
	fmt.Scan(&N)
	fmt.Println(fib(fib(N)) % M)
}
func fib(n int) int {
	if n == 0 {
		return 0
	}
	var A [2][2]int
	A[0][0] = 1
	A[0][1] = 1
	A[1][0] = 1
	A[1][1] = 0
	var B [2][2]int
	for i := range B {
		B[i][i] = 1
	}
	// log.Println(A, B)
	for n > 0 {
		if n&1 == 1 {
			B = mul(B, A)
		}
		A = mul(A, A)
		n >>= 1
	}
	// log.Println(A[1][1], B)
	// log.Println(B[1][0] % M)
	return B[1][0] % M
}

func mul(a, b [2][2]int) [2][2]int {
	var c [2][2]int
	for i := 0; i < len(a); i++ {
		for k := 0; k < len(b); k++ {
			for j := 0; j < len(b[0]); j++ {
				c[i][j] = (c[i][j] + a[i][k]*b[k][j]) % M
			}
		}
	}
	return c
}
0