题意:
求数是否满足不是素数且能满足费马定理。(a ^ n mod n = a)
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <map>
#include <climits>
#include <cassert>
#define LL long long
using namespace std;
const int maxn = 1e6;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
const double pi = 4 * atan(1.0);
const double ee = exp(1.0);
int pow_mod(int a, int n, int mod)
{
if (n == 0)
return 1;
int x = pow_mod(a, n >> 1, mod);
LL ans = (LL)x * x % mod;
if (n % 2)
ans = ans * a % mod;
return ans;
}
bool is_car(int x)
{
for (int i = 2; i <= x - 1; i++)
{
if (pow_mod(i, x, x) != i)
{
return false;
}
}
return true;
}
bool is_prime(int x)
{
int m = sqrt(x);
for (int i = 2; i <= m; i++)
{
if (x % i == 0)
{
return false;
}
}
return true;
}
int main()
{
#ifdef LOCAL
freopen("in.txt", "r", stdin);
#endif // LOCAL
int n;
while (scanf("%d", &n) && n)
{
if (is_prime(n))
{
printf("%d is normal.\n", n);
}
else
{
if (!is_car(n))
{
printf("%d is normal.\n", n);
}
else
{
printf("The number %d is a Carmichael number.\n", n);
}
}
}
return 0;
}