Topic Link: Click to open the link
Test instructions: Give a number n, ask whether this number is Carmichael Numbers,carmichael Numbers is defined as: A number n if not a prime and for any 2=<a<n to satisfy A^n%n=a, So this number is Carmichael Numbers, otherwise not. Quick power to solve the violence.
#include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include < string> #include <cctype> #include <vector> #include <cstdio> #include <cmath> #include < queue> #include <stack> #include <map> #include <set> #define MAXN 65002#define _ll __int64#define ll Long long#define INF 0x3f3f3f3f#define Mod 10000007#define pp pair<int,int> #define ull unsigned long longusing names Pace Std;ll N;bool pri[maxn];void init () {memset (PRI, 1, sizeof (PRI));p ri[0] = 0;pri[1] = 0;for (int i = 2; I * I <= max N i++) {if (Pri[i]) {for (int j = i * i; j <= Maxn; j + = i) {Pri[j] = 0;}}} ll Pow_mod (ll A, ll N, ll p) {if (n = = 0) {return 1;} ll ans = pow_mod (A, N/2, p); ans = ans * ans% p;if (n & 1) {ans = ans * a% P;} return ans;} void Solve () {if (Pri[n]) {printf ("%d is normal.\n", n); return;} for (ll i = 2; i < n; i++) {if (Pow_mod (i, n, n)! = i) {printf ("%d is normal.\n", n); return;}} printf ("The number%D is a Carmichael number.\n ", n);} int main () {init (); while (~SCANF ("%lld", &n) && N) {solve ();} return 0;}
Uva 10006-carmichael Numbers (Fast power)