zoukankan      html  css  js  c++  java
  • virtual hust 2013.6.21 NEFU 挑战编程----数论 B

    题目:Carmichael Numbers

    思路:直接判是不是素数然后满不满足费马小定理就行了

    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    #include <cmath>
    #include <iostream>
    using namespace std;
    #define maxn 66000
    int vis[maxn];
    void Prime()
    {
        memset(vis,1,sizeof(vis));
        vis[0]=vis[1]=0;
        for(int i=2;i*i<maxn;i++)
            if(vis[i])
                for(int j=2*i;j<maxn;j+=i)
                    vis[j]=0;
    }
    long long Pow(long long a,long long b,long long mod)
    {
        long long ans=1;
        while(b)
        {
            if(b&1)
            {
                b--;
                ans=(ans*a)%mod;
            }
            else
            {
                b/=2;
                a=(a*a)%mod;
            }
        }
        return ans;
    }
    bool is_ok(long long n)
    {
        bool ans=1;
        for(int i=2;i<n;i++)
        {
            if(Pow(i,n,n)!=i)
            {
                ans=0;
                break;
            }
        }
        return ans;
    }
    int main()
    {
        Prime();
        int n;
        while(scanf("%d",&n),n)
        {
            if(!vis[n]&&is_ok(n))
                printf("The number %d is a Carmichael number.
    ",n);
            else
                printf("%d is normal.
    ",n);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    缓冲式I/O
    事件轮询接口
    博弈游戏
    多任务I/O之poll函数
    好的link
    做纹理处理的。。。
    快毕业了!
    语音处理的资料
    google图像搜索原理
    install opencv in centos
  • 原文地址:https://www.cnblogs.com/overflow/p/3147897.html
Copyright © 2011-2022 走看看