UVA 10006 Carimichael Numbers(快速幂)
2017-01-28 16:30
429 查看
大年初一无聊刷道题吧…..
【中文题意】给你一个整数,问你它是Carimichael Numbers还是正常数。关于那个Carimichael Numbers定义:我们把对任意的1 < x < n都有x^n恒等x(mod n)成立的合数(不是素数)n称为Carimichael Numbers。
【思路分析】先用筛法预处理一遍所有数,然后再用快速幂判断就好了。
【AC代码】
【中文题意】给你一个整数,问你它是Carimichael Numbers还是正常数。关于那个Carimichael Numbers定义:我们把对任意的1 < x < n都有x^n恒等x(mod n)成立的合数(不是素数)n称为Carimichael Numbers。
【思路分析】先用筛法预处理一遍所有数,然后再用快速幂判断就好了。
【AC代码】
#include<cstdio> #include<map> #include<vector> #include<set> #include<queue> #include<stack> #include<cstring> #include<algorithm> using namespace std; #define LL long long bool is_prime[70000]; void init() { memset(is_prime,1,sizeof(is_prime)); is_prime[2]=0; for(int i=2;i<70000;i++) { if(is_prime[i]) { for(int j=i*2;j<70000;j+=i) { is_prime[j]=false; } } } } LL mod_pow(LL x,LL n,LL mod) { LL res=1; while(n>0) { if(n&1) res=res*x%mod; x=x*x%mod; n>>=1; } return res; } int main() { LL n; init(); while(~scanf("%lld",&n)) { if(n==0)break; if(is_prime ) { printf("%lld is normal.\n",n); continue; } int flag=0; for(LL i=2;i<n;i++) { if(mod_pow(i,n,n)!=i) { flag=1;break; } } if(flag==0) { printf("The number %lld is a Carmichael number.\n",n); } else { printf("%lld is normal.\n",n); } } return 0; }
相关文章推荐
- UVA 10006 - Carmichael Numbers 快速幂
- Uva 10006 Carmichael Numbers 快速幂
- Uva 10006 - Carmichael Numbers【素数+快速幂取模】
- UVA 10006 - Carmichael Numbers 快速幂
- UVA10006->素数筛&&快速幂取模
- UVA 10006 - Carmichael Numbers 数论(快速幂取模 + 筛法求素数)
- Uva 10006 Carmichael Numbers (快速幂)
- Uva 10006 Carmichael Numbers(数论、快速幂、素数筛法)
- UVa 10006 Carmichael Numbers (快速幂 + 素性测试)
- UVA10006-快速幂Carmichael Numbers
- UVa 10006 Carmichael Numbers 【快速幂+素数打表(埃氏筛法)】
- UVA 10006 Carmichael Numbers(快速幂取模)
- uva 10006 Carmichael Numbers(快速幂)
- Uva10006【快速幂】java题解
- UVa 10006 Carmichael Numbers(快速幂取模)
- UVA10006 快速幂
- 快速幂--uva10006
- UVA 10006 - Carmichael Numbers(快速幂取模)
- Uva 10006-Carmichael Numbers(快速幂)
- UVA 10006 - Carmichael Numbers (快速幂+筛素数)