当前位置:  开发笔记 > 编程语言 > 正文

如何在Sage中获得给定长度的素数?

如何解决《如何在Sage中获得给定长度的素数?》经验,为你挑选了1个好方法。

如何在Sage中获得给定位长的随机素数?

例如,为了获得512位素数,我试过了

p = random_prime(2^512)

但根据文件:

命令random_prime(a,True)将返回2和a之间的随机素数

所以我不能使用它,因为我需要一个精确长度的素数.



1> kcrisman..:
sage: random_prime?
Signature:      random_prime(n, proof=None, lbound=2)
Docstring:
   Returns a random prime p between lbound and n (i.e. lbound <= p <=
   n). The returned prime is chosen uniformly at random from the set
   of prime numbers less than or equal to n.

   INPUT:

   * "n" - an integer >= 2.

   * "proof" - bool or None (default: None) If False, the function
     uses a pseudo-primality test, which is much faster for really big
     numbers but does not provide a proof of primality. If None, uses
     the global default (see "sage.structure.proof.proof")

   * "lbound" - an integer >= 2 lower bound for the chosen primes

这样就够了吗?

sage: random_prime(2^512-1,False,2^511)
7484165189517896027318192121767201416039872004910529422703501933303497309177247161202453673508851750059292999942026203470027056226694857512284815420448467
sage: is_prime(7484165189517896027318192121767201416039872004910529422703501933303497309177247161202453673508851750059292999942026203470027056226694857512284815420448467)
True

推荐阅读
云聪京初瑞子_617
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有