-
Notifications
You must be signed in to change notification settings - Fork 0
/
uva10006.cpp
94 lines (80 loc) · 2.09 KB
/
uva10006.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using namespace std;
#include<iostream>
#include<cstring>
#include<cstdio>
#define N 65000+10
bool prime[N];
//int primes[N];
void sieve()
{
//memset(prime,false,sizeof(false));
long long i,j=0,k;
prime[0]=prime[1]=true;
for(i=4;i<N;i+=2)
prime[i]=true;
//primes[j++]=2;
//cout<<"done"<<endl;
for(i=3;i<N;i+=2)
{
//cout<<"done"<<endl;
if(prime[i]==false)
{
//primes[j++]=i;
for(k=i*i;k<N;k+=2*i)
prime[k]=true;
}
}
}
long long big_mod(long long n,long long p,long long m)
{
if(p==1) return n%m;
if(p%2==0)
{
long long temp=big_mod(n,p/2,m);
return ((temp%m)*(temp%m))%m;
}
long long temp=big_mod(n,p-1,m);
return ((temp%m)*(n%m))%m;
}
int main()
{
long long n,i;
sieve();
// cout<<"done"<<endl;
while(scanf("%lld",&n)==1&&n)
{
if(prime[n]==false)
{
printf("%lld is normal.\n",n);
//cout<<n<<endl;
}
else
{
bool flag=true;
for(i=2;i<n;i++)
{
if(big_mod(i,n,n)!=i)
{
flag=false;
break;
}
}
if(flag)
printf("The number %lld is a Carmichael number.\n",n);
else
printf("%lld is normal.\n",n);
}
}
return 0;
}
/*bool carmichael_number(int i,int n)
{
long long j,temp=1;
for(j=0;j<n;j++)
{
temp=((temp%n)*(i%n))%n;
}
if(temp==i)
return true;
return false;
}*/