File size: 1,125 Bytes
c4b0eef |
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 |
#include <iostream>
#include <bitset>
#include <unordered_set>
using namespace std;
typedef long long ll;
typedef unordered_set<int> usi;
ll sieve_size;
bitset<10000000> bs;
usi primes, carmichael;
void sieve(ll upperbound = 65000) {
sieve_size=upperbound+1; bs.set(); bs[0]=bs[1]=0;
for (ll i=2; i<=sieve_size; i++) if(bs[i]) {
for (ll j=i*i; j<=sieve_size; j+=i) bs[j] = 0;
primes.insert((int)i);
}
}
long long pwr(long long b, long long e, long long mod) {
if (e == 0) return 1%mod;
if (e == 1) return b%mod;
long long aux = pwr(b, e/2, mod);
aux = (aux*aux)%mod;
if (e%2) aux = (aux*(b%mod))%mod;
return aux;
}
int main() {
sieve();
for (int i = 3; i <= 65000; i++) {
if (primes.count(i)) continue;
bool ok = true;
for (int j = 2; j < i && ok; j++) {
ok = pwr(j, i, i) == j;
}
if (ok) carmichael.insert(i);
}
int n;
while (cin >> n && n) {
if (carmichael.count(n)) printf("The number %d is a Carmichael number.\n", n);
else printf("%d is normal.\n", n);
}
return 0;
}
|