func main() { num := new(big.Int) num = num.MulRange(1, 100) sum := 0 for _, v := range num.String() { sum += int(v - '0') } fmt.Println(sum) }
func main() { n := new(big.Int) n.MulRange(1, 100) sum := 0 for _, d := range n.String() { sum += int(d) - int('0') } fmt.Printf("%v\n", sum) }
func factorial(x float64) float64 { if x != float64(uint64(x)) { panic("Factorial input must be a positive integer.") } var res *big.Int = new(big.Int) res.MulRange(1, int64(x)) return float64(res.Int64()) }
func main() { var n big.Int n.MulRange(1, 100) var sum int for _, c := range n.String() { sum += int(c - '0') } fmt.Println(sum) }
func main() { sumOfDigits := 0 var value big.Int value.MulRange(1, 100) for _, char := range value.String() { charAsInt, _ := strconv.Atoi(string(char)) sumOfDigits += charAsInt } fmt.Println(sumOfDigits) }
func main() { factorial := new(big.Int) // make a new big.Int factorial.MulRange(1, 100) // The Go package math.big has method MulRange which when called with first param 1, it returns the second param as its factorial value strFactorial := factorial.String() // a big.Int can be converted to a string using it's String() method var total int64 = 0 // intialise a variable to count for _, v := range strFactorial { // for each character in the string strFactorial sv := string(v) // convert the value which is type byte to type string iv, _ := strconv.ParseInt(sv, 10, 64) // parse the string value into an int64 total = total + iv // add each value to the total } fmt.Println(total) }
func sumDigitsFac(num int64) int64 { n := new(big.Int) n.MulRange(1, num) ten := big.NewInt(10) d := new(big.Int) var sum int64 for n.BitLen() > 0 { n.DivMod(n, ten, d) sum += d.Int64() } return sum }
func main() { var count int var a, b big.Int for n := int64(1); n <= 100; n++ { for r := int64(0); r <= n; r++ { a.MulRange(r+1, n) b.MulRange(1, n-r) a.Div(&a, &b) b.SetInt64(1000000) if a.Cmp(&b) > 0 { count++ } } } fmt.Println(count) }
func prob53() { combi := func(n, r int) *big.Int { r1 := new(big.Int) r1.MulRange(int64(n-r+1), int64(n)) r2 := new(big.Int) r2.MulRange(1, int64(r)) r1.Div(r1, r2) return r1 } limit := big.NewInt(1000000) a := 0 for n := 1; n <= 100; n++ { for r := 1; r <= n; r++ { c := combi(n, r) if c.Cmp(limit) > 0 { a++ } } } fmt.Println(a) }
func Factorial(input int) *big.Int { x := new(big.Int) x.MulRange(1, int64(input)) return x }
func factorial(n int) *big.Int { x := new(big.Int) x.MulRange(1, int64(n)) return x }
func factorial(n int64) *big.Int { var z big.Int return z.MulRange(1, n) }
func fact_big(max int64, res *big.Int) { res.MulRange(1, max) return }
func factorial(n int) *big.Int { fac := new(big.Int) fac.MulRange(1, int64(n)) return fac }