UVA 10006_Carmichael number
题意:
N 为合数,对于任意一个在
分析:
素数区间筛法+快速幂
代码:
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
typedef long long ll;
const int maxn = 65005;
const int mod = 1e9;
int isprime[maxn], ok[maxn];
ll quick_pow(int x, int n)
{
ll res = 1;
int mod = n;
while(n){
if(n&1) res = ((ll)res * x)%mod;
x = ((ll)x * x)%mod;
n>>=1;
}
return res;
}
int main (void)
{
int n;
fill(ok, ok +maxn, 0);
fill(isprime, isprime + maxn, 1);
for(int i = 2; i * i <= maxn; i++)
if(isprime[i])
for(int j = 2 * i; j < maxn; j+=i) isprime[j] = 0;
while(~scanf("%d",&n)&&n){
int flag = 1;
if(isprime[n]) flag = 0;
if(flag){
for(int i = 2 ; i < n; i++){
if(quick_pow(i,n)!=i){
flag = 0;
break;
}
}
}
if(flag) printf("The number %d is a Carmichael number.\n", n);
else printf("%d is normal.\n", n);
}
return 0;
}
该死一个句号WA我一万年,为什么不是PE???