计算功率(a,b)%n其中b和n是大的Uint64_t

发布于 2025-01-27 11:45:40 字数 594 浏览 2 评论 0原文

我正在玩 https://en.wikipedia.org/wiki/ Miller%E2%80%93Rabin_primality_test

我想测试uint64_t是否是PRIME。为此,我需要计算pow(a,b)%n其中a< = 37bn n 可以是大uint64_t值。我知道我可以在每个步骤中使用goRithm进行pow(a,b)。但这仍然留下2个有问题的操作:(x * x)%n(x * a)%n

我想知道,是否有比将所有物品分成低和高32位的更好的东西,并在其余部分进行长时间的乘法和长距离的划分。

PS:不要以为有128位整数类型

I'm playing around with https://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test

I want to test if a uint64_t is prime or not. For that I need to compute pow(a, b) % n where a <= 37 but b and n can be large uint64_t values. I know I can compute pow(a, b) with the square-and-multiply algorithm doing % n in every step. But that still leaves 2 problematic operations: (x * x) % n and (x * a) % n.

I wonder if there is something better than splitting everything into low and high 32bit and doing long multiplication and long division for the remainder.

PS: don't assume there is a 128bit integer type

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文