smooth质数

p-1光滑

当 p 是 N 的因数,并且 p - 1 是光滑的时候,可能可以使用 Pollard's p − 1 算法来分解 N,但是也不是完全可以成功的。
参考 https://www.cnblogs.com/lordtianqiyi/articles/17069448.html

p+1光滑

当 p 是 n 的因数,并且 p + 1 是光滑的时候,可能可以使用 Williams's p + 1 算法来分解 N,但是也不是完全可以成功的。
参考 https://www.cnblogs.com/lordtianqiyi/articles/17069456.html

python primefac 库分解大整数

脚本使用
# Williams's p+1 算法 分解大整数 import primefac re = primefac.williams_pp1(n=7941371739956577280160664419383740967516918938781306610817149744988379280561359039016508679365806108722198157199058807892703837558280678711420411242914059658055366348123106473335186505617418956630780649894945233345985279471106888635177256011468979083320605103256178446993230320443790240285158260236926519042413378204298514714890725325831769281505530787739922007367026883959544239568886349070557272869042275528961483412544495589811933856131557221673534170105409) # pollard's p-1算法分解大整数 res = primefac.pollard_pm1(n=1224542620373200232525165378018470774334801515191193204875465445916504222883935188890019876845076388385357911730689547124547346252951158814249284724565588433721828377715469374541007756509231399263095022024229078845538543233785364809917406108015271780070196140628158427541531563472532516237632553353655535922926443707617182025475004547531104052989085765070550150028833424395972178427807901747932614235844448614858629761183210600428438018388051958214596857405813088470933109693499438012040822262549119751099008671892966082341548512112435591881692782766559736840448702039918465573051130405935280702181505538733234675792472428666968900055706926735800561218167237812066851519973807203332801575980055838563085817664973968944323258406789203078387708964307931318918136664885818917720073433998810127482159223895026085726623747340692196977140382318293090736558135980651252533606603312148824142669800602887109353065489282386215179238458743567166284295855288783740314247952124965482197632971993708775190564519250754150756867653033527903848903210074426177258586450311109023467944412194124015505951966140443860862968311560843608415723549525497729679097936310538451467530605937684408079363677707513923579164067808729408365886209340192468399685190639)
命令行使用
This is primefac version 2.0.11. USAGE: primefac [-vs|-sv] [-v|--verbose] [-s|--summary|--summarize] [-t=NUMBER] [-r=NUMBER] [-m=[prb][,p-1][,p+1][,ecm][,siqs]] rpn
The value "rpn" is an expression in reverse Polish notation, also called postfix notation, and is evaluated using integer arithmetic. The values that remain on the stack after evaluation are then factored in sequence. "-t" specifies the largest prime to use for trial division. The default value for this parameter is 1000. Using "-t=inf" will make primefac use trial division exclusively. "-r" is the number of iterations of Pollard's rho algorithm to do before calling a cofactor "difficult". Default == 42,000. Use "-r=inf" to use Pollard's rho algorithm exclusively once trial division is completed. If verbosity is invoked, then we provide progress reports and also state which algorithms produced which factors during the multifactor phase. If the summary and verbosity flags are absent, then the output should be identical to the output of the GNU factor command, modulo permutation of the factors. If the verbosity flag is invoked, then we provide progress reports, turn on the summary flag, and state which methods yielded which factors during the multifactor phase. If the summary flag is present, then the output is modified by including a single newline between each item's output, before the first, and after the last. Each item's output is also modified by printing a second line of data summarizing the results by indicating the number of digits (base 10) in the input, the number of digits (base 10) in each factor, and the factors' multiplicities. For example: >>> user@computer:~$ primefac -s 24 ! 1 - 7 f >>> >>> 620448401733239439359999: 991459181683 625793187653 >>> Z24 = P12 x P12 = 625793187653 x 991459181683 >>> >>> 5040: 2 2 2 2 3 3 5 7 >>> Z4 = P1^4 x P1^2 x P1 x P1 = 2^4 x 3^2 x 5 x 7 >>> >>> user@computer:~$ Note that primes in the ordinary output lines are listed in the order in which they were found, while primes in the summary lines are reported in strictly-increasing order. The -v and -s flags may be collapsed into a single flag, -vs or -sv, but recall that -v implies -s. The "-m" flag controls what methods are used during the difficult-factor phase. The "prb" and "ecm" options can be provided several times to use multiple concurrent instances of these methods. Concurrent applications of the p-1, p+1, or SIQS methods confers no benefit over a single usage, so repeated listings of those methods are ignored. This program can be imported into Python scripts as a module; however, I recommend importing them from the module "labmath" instead. This module is available via pip (https://pypi.org/project/labmath/).
缺点

使用primefac有一些问题:
比如res的值久久求不出来,但我们要是使用脚本来跑的话,2min内就能跑出结果
经过少量实践初步验证,如果已知p-1或者p+1是光滑数,还是套用上面给的算法更好。有的时候p-1可能因子太多而形成指数爆炸,primefac针对这一点处理的不够好。


__EOF__

本文作者_TLSN
本文链接https://www.cnblogs.com/lordtianqiyi/articles/17069463.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   TLSN  阅读(178)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示