ds9567 2017-10-07 06:02
浏览 80
已采纳

去除以大数(big.Int)

I'm trying to divide two massive numbers (e.g. trying to divide 50! by 18!) and I have two big.Int variables set.

first.MulRange(1,50)

second.MulRange(1,18)

How can I divide the numbers (ideally with integer division)?

Thanks!

  • 写回答

1条回答 默认 最新

  • douxuan1284 2017-10-07 06:35
    关注

    How can I divide the numbers

    By invoking Div() method of Int (in this case) data type. ("math/big" package)

    first := new(big.Int).MulRange(1, 50)
    second := new(big.Int).MulRange(1, 18)
    
    fmt.Printf("First: %s 
    ", first.String())
    fmt.Printf("Second: %s 
    ", second.String())
    // division
    dv := new(big.Int).Div(first, second)
    
    fmt.Printf("Division result: %s 
    ", dv.String())
    

    The result:

    First: 30414093201713378043612608166064768844377641568960512000000000000
    Second: 6402373705728000
    Division result: 4750440164794325701367714688167999176704000000000
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?