zoukankan      html  css  js  c++  java
  • UVA 10006_Carmichael number

    题意:

    N 为合数,对于任意一个在(1,N)之间的数满足 anmodn=a,则称N为Carmichael number,对于给定的N,判断是否为Carmichael number。

    分析:

    素数区间筛法+快速幂

    代码:

    #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);
            else  printf("%d is normal.
    ", n);
    
        }
         return 0;
    }
    

    该死一个句号WA我一万年,为什么不是PE???

  • 相关阅读:
    .java中如何实现序列化,有什么意义
    缓存穿透
    缓存击穿
    缓存雪崩
    redis缓存预热
    Docket 的常用命令
    数据库优化方法
    servlet和jsp的区别:
    6原则1法则
    学习IntelliJ IDEA(二)模块
  • 原文地址:https://www.cnblogs.com/Tuesdayzz/p/5758813.html
Copyright © 2011-2022 走看看