Esempio n. 1
0
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)
}
Esempio n. 2
0
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)
}
Esempio n. 3
0
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())
}
Esempio n. 4
0
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)
}
Esempio n. 5
0
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)
}
Esempio n. 6
0
File: 20.go Progetto: Rosalita/euler
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)
}
Esempio n. 7
0
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
}
Esempio n. 8
0
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)
}
Esempio n. 9
0
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)
}
Esempio n. 10
0
func Factorial(input int) *big.Int {
	x := new(big.Int)
	x.MulRange(1, int64(input))
	return x
}
Esempio n. 11
0
func factorial(n int) *big.Int {
	x := new(big.Int)
	x.MulRange(1, int64(n))
	return x
}
Esempio n. 12
0
func factorial(n int64) *big.Int {
	var z big.Int
	return z.MulRange(1, n)
}
Esempio n. 13
0
func fact_big(max int64, res *big.Int) {
	res.MulRange(1, max)
	return
}
Esempio n. 14
0
func factorial(n int) *big.Int {
	fac := new(big.Int)
	fac.MulRange(1, int64(n))
	return fac
}