Miller_Rabin和Pollard Rho算法
2015-11-04 21:49
288 查看
废话不说贴代码
Pollard Rho
Miller_Rabin
Miller_Rabin
Pollard Rho
Miller_Rabin
Miller_Rabin
bool miller_rabin(LL aa,LL p) { int cnt=0; LL res=p-1,u; while(res%2==0) { res/=2; cnt++; } u=ksm(aa,res,p); if(u==1)return 1; for(int i=0;i<cnt;i++) { if(u==p-1)return 1; u=mul(u,u,p); } return 0; } bool isprime(LL p) { if(p==2)return 1; if(p%2==0)return 0; for(int i=0;i<10;i++) { if(p==a[i])return 1; if(!(miller_rabin(a[i],p)))return 0; } return 1; } LL find_fac(LL p) { if(p==4)return 2; while(1) { LL c=rand()%p; LL v=0,u=0,d=0; while(1) { v=(mul(v,v,p)+c)%p; u=(mul(u,u,p)+c)%p; u=(mul(u,u,p)+c)%p; d=gcd(abs(u-v),p); if(d==p)break; if(d>1)return d; } } } void rho(LL p) { if(p==1)return; if(isprime(p)) { pr.insert(p); } else { LL d=find_fac(p); rho(d); rho(p/d); } }
相关文章推荐
- 强联通分量-kosaraju
- nib与xib浅析
- Postgresql及mongodb下载
- There is no Action mapped for namespace
- 深入理解 Java final 变量的内存模型
- 【Android】ArrayList通过remove方法删除元素对象源码分析
- poj 1061 青蛙的约会 【扩展欧几里得】
- Java 中的 ByteArrayOutputStream 应用风险
- android自定义加载动画
- LCIS
- MIT6.828 Lab4 PartA
- 合唱队形
- struts2文件上传下载
- iOS 明明存在的头文件,导入时却提示找不到。
- 隐马尔科夫模型
- Win32 API使用
- 网络性能研究的指挥棒
- 理解Java中的弱引用
- LightOJ 1248 Dice (III)
- JSP九大内置对象的作用和用法总结