本文整理汇总了Golang中math/big.Int.MulRange方法的典型用法代码示例。如果您正苦于以下问题:Golang Int.MulRange方法的具体用法?Golang Int.MulRange怎么用?Golang Int.MulRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类math/big.Int
的用法示例。
在下文中一共展示了Int.MulRange方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
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)
}
示例2: main
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)
}
示例3: factorial
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())
}
示例4: main
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)
}
示例5: main
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)
}
示例6: main
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)
}
示例7: sumDigitsFac
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
}
示例8: prob53
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)
}
示例9: Factorial
func Factorial(input int) *big.Int {
x := new(big.Int)
x.MulRange(1, int64(input))
return x
}
示例10: factorial
func factorial(n int) *big.Int {
x := new(big.Int)
x.MulRange(1, int64(n))
return x
}
示例11: factorial
func factorial(n int64) *big.Int {
var z big.Int
return z.MulRange(1, n)
}
示例12: fact_big
func fact_big(max int64, res *big.Int) {
res.MulRange(1, max)
return
}
示例13: factorial
func factorial(n int) *big.Int {
fac := new(big.Int)
fac.MulRange(1, int64(n))
return fac
}