标签:amp 迈克尔 typedef 参考 ble 很多 prim 输入 密码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//尚不是特别大的数嘞!
//打表计算素数
int prime[65000];
void f()
{
prime[0]=prime[1]=0;
for(int i=2;i<65000;i++) prime[i]=1;
for(int i=2;i<65000;i++)
if(prime[i])
for(int j=2*i;j<65000;j+=i)
prime[j]=0;
}
ll qmod(ll a,ll b,ll m)//计算a^b MOD m
{
ll ans=1;
while(b)
{
if(b&1) ans=(ans*a)%m;
b>>=1;
a=(a*a)%m;
}
return ans;
}
int tests(int n)
{
for(int i=2;i<=n-1;i++)
if(qmod(i,n,n)!=i) return 0;//点睛巨笔!
return 1;
}
int main()
{
f();
int n;
while(cin>>n&&n)
{
if(!prime[n] && tests(n))
cout<<"The number "<<n<<" is a Carmichael number.\n";
else cout<<n<<" is normal.\n";
}
return 0;
}
附录:https://vjudge.net/contest/310908#problem/A
标签:amp 迈克尔 typedef 参考 ble 很多 prim 输入 密码
原文地址:https://www.cnblogs.com/dragondragon/p/11350433.html