如何使用 GMP 求 2 除法的最大幂?

发布于 2024-09-28 13:39:36 字数 570 浏览 1 评论 0原文

根据 GMP 文档此处

功能:unsigned long int mpz_remove (mpz_t rop,mpz_t op,mpz_t f)

删除所有出现的因子 f 来自 op 并将结果存储在 rop 中。 返回值是有多少个这样的 事件已被删除。

所以 mpz_remove 函数应该能够用来回答标题问题。目前我的代码如下所示:

  mpz_set_ui(temp2,2);
  mpz_remove(temp,K0,temp2);

工作正常,但我想要的结果是 K0 除以 temp (而不是 temp 本身)[我可以通过添加后续除法运算来获得它,但这似乎很浪费]。

我应该如何实际获得 K0/temp?

According to the GMP documentation here:

Function: unsigned long int mpz_remove
(mpz_t rop, mpz_t op, mpz_t f)

Remove all occurrences of the factor f
from op and store the result in rop.
The return value is how many such
occurrences were removed.

So the mpz_remove function should be able to be used to answer the titled question. At the moment my code looks like this:

  mpz_set_ui(temp2,2);
  mpz_remove(temp,K0,temp2);

which works fine, but the result I want is K0 divided by temp (and not temp itself) [which I could get by adding a subsequent division operation, but that seems wasteful].

How should I actually get K0/temp?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

毁我热情 2024-10-05 13:39:36

您可以尝试组合使用 mpz_scan1() 和 mpz_tdiv_q_2exp()。

mpz_tdiv_q_2exp(result,K0,mpz_scan1(K0,0))

You might try the combination of mpz_scan1() and mpz_tdiv_q_2exp().

mpz_tdiv_q_2exp(result,K0,mpz_scan1(K0,0))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文