MillerRabin 快速的素数概率判定法
来源:互联网 发布:mysql sum group by 编辑:程序博客网 时间:2024/05/16 08:59
MillerRabin 快速的素数概率判定法
1.作用:快速判断单个数是否为质数
2.原理:
介绍费马小定理:对于每一个素数p,都有
但是不是对于每一个有
如果存在b满足上述规则,那么b有3/4的几率为素数
MillerRabin通过多次随机生成b并使用以上方法进行判断,能把错误的几率降到
分母指数级扩大让概率随k的增大迅速趋近于0。当k达到10时判断错误的几率已经降到百万分之一,k达到20时几乎不会出错。
黑科技的力量啊 = =
typedef long long LL;namespace millerrabin{ inline LL advpow(LL a,LL b,LL c){ LL ret=1; while(b){ if(b&1)ret*=a,ret%=c; a*=a; a%=c; b>>=1; } return ret; } int random(const int&mod){ srand(rand()*rand()*rand()); return rand()%mod; } bool jdPrime(const int&num,const int&eps){ if(num<=3)return true; int cnt=0; while(cnt<=eps){ int a=random(num)+2; if(num%a==0)continue; if(advpow(a,num-1,num)%num!=1)return false; cnt++; } return true; }}
2 0
- MillerRabin 快速的素数概率判定法
- ZOJ3758:Singles' Day(快速素数判定法)
- 快速判定素数
- (Relax 快速幂取模1.4)POJ 3641 Pseudoprime numbers(快速幂取模+大素数MillerRabin模板题)
- 算法杂项:快速判定素数(素数表)
- 素数的判定
- 素数的判定
- 素数的判定
- 素数的判定
- 素数的判定二
- MillerRabin质数判定+PollardRho质因子分解
- 素数 快速判定并打表
- POJ 3641 -- 快速幂运算,素数判定
- MillerRabin
- 随机算法 MillerRabin素数测试是3/4正确的蒙特卡洛算法
- MillerRabin 素数测试【摘自旧博】
- 素数的Miller_Rabbin判定算法
- hdu 2012 素数的判定
- onenote无法打开链接出现错误您的组织策略阻止我们为您完成此操作
- hdu5671 Conturbatio(思维)
- uva 1543 dp
- J2SE 利用Java函数画曲线
- 使用WindowManager.addView()模拟直播软件悬浮窗口播放视频
- MillerRabin 快速的素数概率判定法
- Java BigInteger相关知识点
- Spark分布式计算和RDD模型研究
- 侧滑菜单-自定义HorizaontalScrollView
- HDU 1009FatMouse' Trade
- Hdu-4507 吉哥系列故事——恨7不成妻(数位DP)
- 类加载,构造器初始化及static关键字
- CSDN-markdown编辑器使用方式
- Log4net 简明手册