Commits

Miki Tebeka committed 4d8cca1

Using big

  • Participants
  • Parent commits d340bc7

Comments (0)

Files changed (1)

 package main
 
 import (
+	"big"
 	"flag"
 	"fmt"
 	"os"
 	"strconv"
 )
 
-func fib(n int) []uint64 {
-	var a, b uint64
-	fibs := make([]uint64, n)
-	a, b = 1, 1
+func fib(n int) *big.Int {
+	a, b := big.NewInt(1), big.NewInt(1)
+	tmp := big.NewInt(0)
 	for i := 0; i < n-1; i++ {
-		fibs[i] = a
-		a, b = b, a+b
+		tmp.Set(a)
+		a.Set(b)
+		b.Add(tmp, b)
 	}
-	fibs[n-1] = a
-
-	return fibs
+	return b
 }
 
 func main() {