#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<ctime>
#include<cmath>
#include<iostream>
using namespace std; #define LL long long
LL n;
#define maxs 80
LL fac[maxs],num[maxs],lf=;
LL mul(LL a,LL b,LL p)
{
LL tmp=a,ans=;
while (b) {if (b&) ans=(ans+tmp)%p;tmp=(tmp+tmp)%p;b>>=;}
return ans;
}
LL random(LL x) {return (LL)((double)rand()/RAND_MAX*(x-)+0.5);}
LL f(LL x,LL c,LL p) {return (mul(x,x,p)+c)%p;}
LL gcd(LL a,LL b) {if (a<b) return gcd(b,a);return b?gcd(b,a%b):a;}
LL play(LL x,LL c)
{
LL a=random(x-)+,b=f(a,c,x),i=,k=;
if (a==b) return x;
while (++i)
{
LL sig=gcd(fabs(a-b),x);
if (sig> && sig<x) return sig;
b=f(b,c,x);
if (a==b) return x;
if (i==k) a=b,k<<=;
}
}
LL pow_mod(LL a,LL b,LL p)
{
LL tmp=a,ans=;
while (b) {if (b&) ans=mul(ans,tmp,p);tmp=mul(tmp,tmp,p);b>>=;}
return ans;
}
bool is_prime(LL x)
{
LL num=x-,k=;while (!(num&)) num>>=,k++;
for (int i=;i<=;i++)
{
LL t=random(x-)+,jud=pow_mod(t,num,x),now=jud;
for (int j=;j<=k;j++)
{
jud=mul(jud,jud,x);
if (jud== && now!= && now!=x-) return ;
now=jud;
}
if (jud!=) return ;
}
return ;
}
void rho(LL x,LL c)
{
if (x==) return;
if (is_prime(x)) {fac[++lf]=x;return;}
LL p=x,tmp=c;
while (p==x) p=play(x,tmp--);
rho(p,c);rho(x/p,c);
}
int main()
{
srand(time(NULL));
scanf("%lld",&n);
memset(fac,,sizeof(fac));
rho(n,);sort(fac+,fac++lf);num[]=;LL nlf=;
for (int i=;i<=lf;i++)
if (fac[i-]==fac[i]) num[nlf]++;
else num[++nlf]=,fac[nlf]=fac[i];
lf=nlf;
for (int i=;i<lf;i++) printf("%lld^%lld*",fac[i],num[i]);printf("%lld^%lld\n",fac[lf],num[lf]);
return ;
}

Pollard rho模板的更多相关文章

  1. POJ 1811 Prime Test (Pollard rho 大整数分解)

    题意:给出一个N,若N为素数,输出Prime.若为合数,输出最小的素因子.思路:Pollard rho大整数分解,模板题 #include <iostream> #include < ...

  2. Miller-Rabin 素性测试 与 Pollard Rho 大整数分解

    \(\\\) Miller-Rabin 素性测试 考虑如何检验一个数字是否为素数. 经典的试除法复杂度 \(O(\sqrt N)\) 适用于询问 \(N\le 10^{16}\) 的时候. 如果我们要 ...

  3. Pollard Rho算法浅谈

    Pollard Rho介绍 Pollard Rho算法是Pollard[1]在1975年[2]发明的一种将大整数因数分解的算法 其中Pollard来源于发明者Pollard的姓,Rho则来自内部伪随机 ...

  4. Miller Rabin素数检测与Pollard Rho算法

    一些前置知识可以看一下我的联赛前数学知识 如何判断一个数是否为质数 方法一:试除法 扫描\(2\sim \sqrt{n}\)之间的所有整数,依次检查它们能否整除\(n\),若都不能整除,则\(n\)是 ...

  5. 整数(质因子)分解(Pollard rho大整数分解)

    整数分解,又称质因子分解.在数学中,整数分解问题是指:给出一个正整数,将其写成几个素数的乘积的形式. (每个合数都可以写成几个质数相乘的形式,这几个质数就都叫做这个合数的质因数.) .试除法(适用于范 ...

  6. Pollard Rho因子分解算法

    有一类问题,要求我们将一个正整数x,分解为两个非平凡因子(平凡因子为1与x)的乘积x=ab. 显然我们需要先检测x是否为素数(如果是素数将无解),可以使用Miller-Rabin算法来进行测试. Po ...

  7. Pollard rho算法+Miller Rabin算法 BZOJ 3668 Rabin-Miller算法

    BZOJ 3667: Rabin-Miller算法 Time Limit: 60 Sec  Memory Limit: 512 MBSubmit: 1044  Solved: 322[Submit][ ...

  8. 初学Pollard Rho算法

    前言 \(Pollard\ Rho\)是一个著名的大数质因数分解算法,它的实现基于一个神奇的算法:\(MillerRabin\)素数测试(关于\(MillerRabin\),可以参考这篇博客:初学Mi ...

  9. 【Luogu】P4358密钥破解(Pollard Rho)

    题目链接 容易发现如果我们求出p和q这题就差不多快变成一个sb题了. 于是我们就用Pollard Rho算法进行大数分解. 至于这个算法的原理,emmm 其实也不是很清楚啦 #include<c ...

随机推荐

  1. 序列化shelve模块

    1.shelve对pickle进行封装,所以shelve也只能在python里使用. shelve可以进行多次dump而且顺序不会乱. import shelve f = shelve.open('s ...

  2. js事件、Js中的for循环和事件的关系、this

    一.js事件  1.事件 用户在网页中所触发的行为 鼠标滑动种类很多,键盘.表单特列: 点击:onclick 鼠标进入:onmouseenter 鼠标离开:onmouseleave 鼠标悬浮:onmo ...

  3. css3 blur模糊解决ie6-ie9兼容

    css3 blur模糊是css3的新特性,但是不兼容ie6-ie9,以下代码可以解决此问题: filter: progid:DXImageTransform.Microsoft.Blur(Pixel ...

  4. Git使用简析

    推送本地操作 初始化一个本地Git仓库,在需要添加版本控制的文件夹根目录中使用git init命令. 添加文件到本地Git仓库: git add 文件名 # 添加文件到暂存区 git add . # ...

  5. 【Win32汇编】编译环境配置

    开始学习[Win32汇编],编译过程较为繁琐,做个记录. 使用 MASM32 提供的 ml.exe 和 link.exe,以及 VS2013 中的 nmake.exe 和资源编辑器. ml.exe: ...

  6. 洛谷 P2580 于是他错误的点名开始了

    题目背景 XS中学化学竞赛组教练是一个酷爱炉石的人. 他会一边搓炉石一边点名以至于有一天他连续点到了某个同学两次,然后正好被路过的校长发现了然后就是一顿欧拉欧拉欧拉(详情请见已结束比赛CON900). ...

  7. How to Slove MB SD C4 Cannot Access OBD2 Port

    When using china clone mb sd connect compact 4 Multiplexer, it could not link to the car computer, M ...

  8. C ++ _基础之共用体

    由以下代码来进一步学习共用体 #include <stdio.h> #include<iostream> void main() { union un { int a; cha ...

  9. 雷林鹏分享:Lua 基本语法

    Lua 学习起来非常简单,我们可以创建第一个 Lua 程序! 第一个 Lua 程序 交互式编程 Lua 提供了交互式编程模式.我们可以在命令行中输入程序并立即查看效果. Lua 交互式编程模式可以通过 ...

  10. python之int (整型)

    用途: 用于计算和比较 整型的格式: 10203 123 3340 整型的运算: + - * / ** // % 整数的加: a = 10 b = 20 print(a + b) # 输出结果 30 ...