/*过两天写这两个算法的详解*/
#include <iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<string.h>
using namespace std;
#define ll long long
ll ans = 1;
int n;
const int maxn = 65005;
int a[maxn];
void judge()
{
int m = sqrt(65000+0.5);
memset(a,0,sizeof(a));
for(int i=2;i<=m;i++)
{
if(!a[i])
{
for(int j=i*i;j<65010;j+=i)
a[j]=1;
}
}
}
int powmod(int i,int n,int m)
{
int res = 1;
int tmp = i;
while(n>0)
{
if(n&0x1) res *= tmp;
tmp *= tmp;
n>>=1;
}
res = res%m;
return res;
}
int main()
{
judge();
while(scanf("%d",&n)&&n!=0)
{
if(a[n] != 1) printf("%d is normal.\n",n);
else{
bool flag = true;
for(int i=2;i<n;i++)
{
ans = powmod(i,n,n);
if(ans != i) {flag = false;break;}
}
if(flag == 0) printf("The number %d is a Carmichael number.\n",n);
else printf("%d is normal.\n",n);
}
}
return 0;
}
UVA 10006(素数判断+快速幂)
最新推荐文章于 2018-04-09 20:18:38 发布