程序虽然写出来了,但是不知道如何用一个大数(例如100位的大数)去初始化一个大数变量,比较遗憾!
Go语言程序:
// bigint project main.go
package main
import (
"fmt"
"math"
"math/big"
)
func main() {
// Here are some calculations with bigInts:
im := big.NewInt(math.MaxInt64)
in := im
io := big.NewInt(1956)
ip := big.NewInt(1)
ip.Mul(im, in).Add(ip, im).Div(ip, io)
fmt.Printf("Big Int: %v\n", ip)
iq := big.NewInt(10000)
ip.Mod(ip, iq)
fmt.Printf("Big Int: %v\n", ip)
}
程序运行结果:
Big Int: 43492122561469640008497075573153004
Big Int: 3004
程序说明:
1.math包中包含有各种功能函数,包括最大的整数math.MaxInt64
2.math/big包可以用于大整数计算
3.大整数可以使用"%v"格式输出
参考链接: