Last active
September 19, 2015 06:55
-
-
Save gorakhargosh/f196349d1606d7848616 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"math/big" | |
) | |
// readInt reads an integer from standard input. | |
func readInt() (int, error) { | |
var a int | |
_, err := fmt.Scan(&a) | |
return a, err | |
} | |
// bigFactorial calculates the factorial of an arbitrarily large integer. | |
func bigFactorial(n int64) *big.Int { | |
ret := big.NewInt(1) | |
if n == 0 || n == 1 { | |
return ret | |
} | |
return ret.MulRange(1, n) | |
} | |
func main() { | |
n, err := readInt() | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Println(bigFactorial(int64(n))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment