-
Notifications
You must be signed in to change notification settings - Fork 0
/
UVA 10006.cpp
74 lines (50 loc) · 1.2 KB
/
UVA 10006.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
#include <bits/stdc++.h>
#define pb push_back
#define lp(i,n) for(int i=0; i<n; i++)
#define lli long long int
using namespace std;
int arr[70000];
void prime(){
arr[0]=1;
arr[1]=1;
for(int i=2; i<=70000; i++){
if(!arr[i]){
for(int j=i+i; j<=70000; j+=i){
arr[j]=1;
}
}
}
}
long long int calc(long long int n, long long int k, long long int mod){
if(k==1){
return n%mod;
}
if(k%2==0){
return calc( (n*n)%mod, k/2, mod) %mod;
}else{
return (n*calc((n*n)%mod,k/2,mod))%mod;
}
}
//WE USE LONG LONG INT BECCAUSE THE MAXIMUM INTERMEDIATE PROCESS IS 65000*65000 which cant be handled by int
int main(){
prime();
long long int n;
bool state;
while(true){
state=true;
cin>>n;
if(n==0){
return 0;
}
for(long long int i=2; i<n; i++){
if(calc(i,n,n)%n!=i || arr[n]==0){
cout<<n<<" is normal."<<endl;
state=false;
break;
}
}
if(state){
cout<<"The number "<<n<<" is a Carmichael number."<<endl;
}
}
}