#include<iostream>
#include<time.h>

using namespace std;

long Pow(int a,int b) //计算a的b次方
{
intk;
longs=1;
for(k=1;k<=b;k++)
{
s*=a;
}
returns;
}
bool RandomPrimalityTest(int N) //蒙特卡罗测试
{
srand((unsigned)time(NULL));//初始化随机种子
inta=rand()%N; //随机产生小于N的整数
if(a==0)a=N-1;
longb=Pow(a,N-1)-1;
if(b%N==0)return true;
elsereturn false;
}

void RepeatCall(int N,int n=100) //重复调用RandomPrimalityTest函数n次
{
intk;
intcnt=0;
constdouble precison=0.90; //定义精度
for(k=1;k<=n;k++)if(RandomPrimalityTest(N)) cnt++;
doublee=cnt*1.0/n;
if(e>=precison)cout<<N<<"是素数"<<endl;
elsecout<<N<<"不是素数"<<endl;
}

void main()
{
intN;
cout<<"请输入一个整数:";
cin>>N;
if(!cin.good())
{
cerr<<"输入异常!"<<endl;
cin.clear();
return;
}
RepeatCall(N);
}