当前位置:网站首页>【数论】素数(四):数的分解(Pollard-rho)
【数论】素数(四):数的分解(Pollard-rho)
2022-04-22 06:13:00 【default111】
我的数论-素数部分博客共5part:
基本概念、性质、猜想、定理
素数筛法(埃式筛、欧拉筛、区间筛)
素数判断法(朴素法、模6法、Rabin-Miller及改进)
数的分解(Pollard-rho)
梅森素数(Lucas_Lehmer判定法)
数的分解
普通整数分解
- 枚举因子试除
- 素数打表试除
大整数分解:Pollard-rho
本质:随机因子检查
Pollard的伪随机数生成器: f ( x ) = ( x 2 + c ) m o d N f(x)=(x^2+c)\mod N f(x)=(x2+c)modN ,随机数序列: { x , f ( x ) , f ( f ( x ) ) ⋯ } \{x,f(x),f(f(x))\cdots\} { x,f(x),f(f(x))⋯} 。可以修改参数打表画图得到,这个序列会进入循环,常类似 ρ \rho ρ 型,即经过一些数才进入循环
(这是kuangbin的模板)
ll factor[100]; //质因素分解结果(刚返回时时无序的)
int tol; //质因素的个数,编号 0∼tol-1
//找出一个因子
ll pollard_rho(ll x, ll c)
{
ll i = 1, k = 2;
srand(time(NULL));
ll x0 = rand() % (x - 1) + 1;
ll y = x0;
while (1)
{
i++;
x0 = (multi_add(x0, x0, x) + c) % x;
ll d = __gcd(y - x0, x);
if (d != 1 && d != x)
return d;
if (y == x0)
return x;
if (i == k)
{
y = x0;
k += k;
}
}
}
//对 n 进行素因子分解,存入 factor; k 设置为 107 左右即可
void findfac(ll n, int k)
{
if (n == 1)
return;
if (Miller_Rabin(n))
{
factor[tol++] = n;
return;
}
ll p = n;
int c = k;
while (p >= n)
p = pollard_rho(p, c--); //值变化,防止死循环 k findfac(p,k);
findfac(p, k);
findfac(n / p, k);
}
版权声明
本文为[default111]所创,转载请带上原文链接,感谢
https://blog.csdn.net/default012/article/details/123299940
边栏推荐
- C语言 | i++ 与 ++i
- 【JEECG】修改Viser图表颜色样式
- [bug notes] antd table height adaptive window height
- C语言 | 位运算符
- Pyhon3 批量合并哔哩哔哩缓存的m4s视频文件
- 定义一个抽象的Role类有姓名年龄性别爱好等成员变量要求尽可能隐藏所有变量(能够私有就私有)再通过Get()和Set()方法对各变量进行读写,其中龄必须在0到150岁性别必须是男或者女姓名必须是2个字
- Goodbye, postman. One thing to say: apifox is yyds
- Install and modify the installation path of utools and vscode plug-ins
- Raspberry Pi 4b
- SQL server stored procedure development notes - piecemeal problems and operations on operation files
猜你喜欢

Use of Tencent cloud object storage service

Preparation before analog circuit board commissioning_ Analog circuit board

C语言 | 指针

(四)Sql Server中的字符集(排序规则)

ASP. Net daily development notes ----- IIS server supports downloading APK

ASP.NET日常开发随手记------iis服务器支持下载apk

Install and modify the installation path of utools and vscode plug-ins

SQL server stored procedure development notes - piecemeal problems and operations on operation files

Introduction to IC Analog Layout - learning notes on layout Basics (I)

C语言 | 快速排序
随机推荐
Define an abstract role class with name, age, gender, hobbies and other member variables. It is required to hide all variables as far as possible (private if possible), and then read and write each va
Raspberry Pi 4b
Notes on C # daily development ----- obtain all files in the zip in Huawei cloud bucket (including system. Notsupportedexception: "this stream does not support search operation" solution)
Is it difficult to get started with self-study of Digital IC design? How to get started quickly?
泛型与反射的实际使用练习(包含一个泛型缓存)----手写ORM框架
Help documents on log4net and NLog usage
左移与右移
Install and modify the installation path of utools and vscode plug-ins
假设成年人的体重和身高存在此种关系: 身高(厘米)-100=标准体重(千克) 如果一个人的体重与其标准体重的差值在正负5%之间,显示“体重正常”,其他则显示“体重超标”。编写程序,能处理用户输入的
macOS安装redis并设置服务自启动
ASP.NET日常开发随手记------用文本文档记录日志
Introduction to IC Analog Layout - learning notes on layout Basics (5)
Service configuration center of Nacos
MongoDB安装自启动服务
C语言 | 数组
把上一次作业第一部分,有参数的类,改成无参数方式呈现,功能不变。
Change the class with parameters in the first part of the last operation to be presented in the way without parameters, and the function remains unchanged.
提示用户输入其名字 用户作出响应后 将其名字写 入到文件guest.txt 中 程序判断当不等于n的时候,就执行 创建文件data.txt,文件共10万行,每行存放一个1~100之间的随机一个整数
Prompt the user to enter his name, and the user will write his name to the file guest Txt program determines that when it is not equal to N, it executes to create the file data Txt, a total of 100000
写一个方法sanjiao(a, b, c),判断三个参数是否能构成一个三角形,如果不能则抛出异常IllegalArgumentException,显示异常信息a,b,c”不能构成三角形”,如果可以