Skip to content

Instantly share code, notes, and snippets.

@0xkohe
Created August 10, 2020 10:56
Show Gist options
  • Save 0xkohe/f0562f7b847dab43a2a5e5f1b274a7cb to your computer and use it in GitHub Desktop.
Save 0xkohe/f0562f7b847dab43a2a5e5f1b274a7cb to your computer and use it in GitHub Desktop.
func fibExp(t fibNum, n int) fibNum {
r := t
// 1
a := fibNum{num: big.NewRat(1, 1), numMultipliedBySR: big.NewRat(0, 999)}
for n > 1 {
if n%2 == 1 {
a = fibMul(a, r)
}
r = fibMul(r, r)
n = n / 2
}
return fibMul(r, a)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment