gpt4 book ai didi

c# - 在 .NET 中乘以非常大的整数

转载 作者:行者123 更新时间:2023-11-30 13:21:50 25 4
gpt4 key购买 nike

假设您有像 1253999939979969998746 和 9999999999 这样的大整数。在 C# 中有没有办法将这些大整数相乘?

注意:我试过 System.Numerics.BigInteger 类构造函数编译器说 integer 太长

你有什么建议?

如果这个问题超出主题,请警告我。

最佳答案

你需要使用BigInteger.Parse

BigInteger num = BigInteger.Parse("1253999939979969998746");

如果您尝试使用如下所示的整数值

BigInteger num = 1253999939979969998746;

右侧需要有一个类型,默认情况下是 Int32long。但是由于数字太大而不能成为 Int32long,因此转换失败,因此出现错误。

正如 Tim Schmelter 在评论中指出的那样,要进行乘法运算,您可以执行以下操作:

BigInteger num = BigInteger.Multiply(BigInteger.Parse("1253999939979969998746"), 
BigInteger.Parse("9999999999"));

关于c# - 在 .NET 中乘以非常大的整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37523433/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com