MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / Problem20

Function Problem20

project_euler/problem_20/problem20.go:18–25  ·  view source on GitHub ↗
(input int)

Source from the content-addressed store, hash-verified

16import "math/big"
17
18func Problem20(input int) int {
19 factorial := bigFactorial(input)
20 sum := 0
21 for _, digit := range factorial.String() {
22 sum += int(digit - '0')
23 }
24 return sum
25}
26
27// bigFactorial returns the factorial of n as a big.Int
28// Use big package to handle large numbers

Callers 2

TestProblem20_FuncFunction · 0.85
BenchmarkProblem20_FuncFunction · 0.85

Calls 2

bigFactorialFunction · 0.85
StringMethod · 0.80

Tested by 2

TestProblem20_FuncFunction · 0.68
BenchmarkProblem20_FuncFunction · 0.68