Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
factorial.go
import (
"fmt"
"math/big"
)
func factorial(x *big.Int) *big.Int {
n := big.NewInt(1)
if x.Cmp(big.NewInt(0)) == 0 {
return n
}
return n.Mul(x, factorial(n.Sub(x, n)))
}
func main() {
fmt.Println(factorial(big.NewInt(103)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment