如何在C ++中找到大数除法的余数?

编程入门 行业动态 更新时间:2024-10-09 01:14:26
本文介绍了如何在C ++中找到大数除法的余数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我对C ++中的模数有疑问.我试图做的是将一个非常大的数相除,例如说M%2,其中M = 54,302,495,302,423.但是,当我进行编译时,它表示该数字对于int是"long"的.然后,当我将其切换为双精度时,它会重复相同的错误消息.有什么办法可以使剩下的这个很大的数字,甚至更大的数字呢?感谢您的帮助,非常感谢.

I have a question regarding modulus in C++. What I was trying to do was divide a very large number, lets say for example, M % 2, where M = 54,302,495,302,423. However, when I go to compile it says that the number is to 'long' for int. Then when I switch it to a double it repeats the same error message. Is there a way I can do this in which I will get the remainder of this very large number or possibly an even larger number? Thanks for your help, much appreciated.

推荐答案

对于C ++中的大量算术,请使用 GMP 图书馆.特别是, mpz_mod 函数可以做到这一点.

For large number arithmetic in C++, use the GMP library. In particular, the mpz_mod function would do this.

对于更自然的C ++包装器, mpz_class 类可以通过为多精度操作提供运算符重载来提供帮助.

For a more natural C++ wrapper, the mpz_class class can help by providing operator overloading for multiprecision operations.

更多推荐

如何在C ++中找到大数除法的余数?

本文发布于:2023-11-29 09:04:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1645952.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:余数   除法   大数   中找到   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!