明月笑刀无情
是你的递归算法产生了组合爆炸。使用迭代算法。试试这个迭代算法:package mainimport "fmt"// fibonacci returns the Fibonacci number for 0 <= n <= 92.// OEIS: A000045: Fibonacci numbers:// F(n) = F(n-1) + F(n-2) with F(0) = 0 and F(1) = 1.func fibonacci(n int) int64 { if n < 0 { panic("fibonacci: n < 0") } f := int64(0) a, b := int64(0), int64(1) for i := 0; i <= n; i++ { if a < 0 { panic("fibonacci: overflow") } f, a, b = a, b, a+b } return f}func main() { for _, n := range []int{0, 1, 2, 3, 90, 91, 92} { fmt.Printf("%-2d %d\n", n, fibonacci(n)) }}游乐场: https: //play.golang.org/p/_5CMHZm3Hlo输出:0 01 12 13 290 288006719437081612091 466004661037553030992 7540113804746346429real 0m0.003suser 0m0.002ssys 0m0.000s