素数的Miller_Rabbin测试
来源:互联网 发布:知乎 印度军工 编辑:程序博客网 时间:2024/06/06 03:27
第一个以2为底的强伪素数为2047。第一个以2和3为底的强伪素数则大到1 373 653。
</pre><pre name="code" class="cpp">#include <cstdio>#include <cmath>#include <cstring>#include <string>#include <algorithm>#include <iostream>#include <queue>#include <map>#include <set>#include <vector>using namespace std;const __int64 maxn = 500005;__int64 powe_m(__int64 a,__int64 b,__int64 c){__int64 ans=1; __int64 tmp=a;while(b!=0){ if (b&1) ans=ans*tmp%c; //不可以写 ans=ans*ans%c 结果会变tmp=tmp*tmp%c;b=b>>1;}return ans; }bool test(__int64 n,__int64 a,__int64 d){if (n==2)return true;if (n==a)return true;if ( (n&1)==0) return false;while(!(d&1)) d=d>>1;__int64 t=powe_m(a,d,n);while((d!=n-1) && (t!=1)&&(t!=n-1)){t= (__int64 ) t*t%n;d=d<<1;}return (t==n-1 || (d&1)==1);}bool isprime (__int64 n){if (n<2)return false;__int64 a[]={2,3,61,7,13,17,19,23,29,31,37};for (int i=0;i<11 ;i++)if (!test(n,a[i],n-1))return false;return true;}int main(){int t;int n,i;scanf("%d",&t);while(t--){scanf("%d",&n); if (isprime(n)){printf("yes\n");}else{printf("No\n");} }return 0;}
0 0
- 素数的Miller_Rabbin测试
- 素数的Miller_Rabbin测试
- Miller_Rabbin 素数测试
- 素数的Miller_Rabbin判定算法
- 素数&&Miller_Rabbin
- hdu2138 How many prime numbers(Miller_Rabbin随机素数测试)
- Miller_Rabbin大素数判定 学习笔记
- poj 1811(大素数模版 miller_rabbin素数判定+pollard_rho分解)
- [数论] Miller_Rabbin算法判断大素数,Pollard_rho算法进行质因素分解
- [数论] Miller_Rabbin算法判断大素数,Pollard_rho算法进行质因素分解
- 素数测试
- 素数测试
- 素数测试
- 素数测试
- 素数测试
- 素数测试
- 素数测试
- 素数性测试的蒙特卡罗算法
- Android Activity的生命周期
- C语言-5
- C++对象模型——执行期语意学(第六章)
- 系统函数C字符串的实现(9):strrchr
- SQLite 日期类型
- 素数的Miller_Rabbin测试
- Git 学习之--安装配置GitHub
- TCP协议中的三次握手和四次挥手(图解)
- 保护眼睛——f.lux(linux,windows,mac 均可)
- pat(A) 1007. Maximum Subsequence Sum(和最大子段)
- Linux进程调用原理
- ZOJ - 3469 Food Delivery(区间DP)
- 《Objective-C基础教程》第13章 协议
- Mysql 主从