不知道为什么原来的板子一直T。
所以换了个板子。
讲真,觉得原来的板子没问题啊啊啊啊。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#define ll long long
using namespace std;
const int s=8;
ll maxx=0;
ll mult_mod(ll a,ll b,ll p)
{
a%=p,b%=p;
ll c=(long double)a*b/p;
ll ans=a*b-c*p;
if(ans<0) ans+=p;
else if(ans>=p) ans-=p;
return ans;
}
ll pow_mod(ll a,ll n,ll p)
{
ll ans=1;
a%=p;
while(n)
{
if(n&1) ans=mult_mod(ans,a,p);
a=mult_mod(a,a,p);
n>>=1;
}
return ans;
}
bool check(ll a,ll n, ll x,ll t)
{
ll ret = pow_mod(a,x,n);
ll last=ret;
for(int i=1;i<=t;i++)
{
ret=mult_mod(ret,ret,n);
if(ret==1&&last!=1&&last!=n-1) return true;
last=ret;
}
if(ret!=1) return true;
else return false;
}
bool Miller_Rabin(ll n)
{
if(n<2) return false;
if(n==2) return true;
if((n&1)==0) return false;
ll x=n-1;
ll t=0;
while((x&1)==0)
{
x>>=1;
t++;
}
srand(time(NULL));
for(int i=0;i<s;i++)
{
ll a=rand()%(n-1)+1;
if(check(a,n,x,t))
return false;
}
return true;
}
ll gcd(ll a,ll b)
{
ll t;
while(b)
{
t=a;
a=b;
b=t%b;
}
if(a>=0) return a;
else return -a;
}
ll Pollard_rho(ll x)
{
ll s=0,t=0,c=rand()%(x