• 素数打表


    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <cmath>
    #include<vector>
    #include<algorithm>
    
    using namespace std;
    typedef long long LL;
    
    const int maxn=1000007;
    const int INF=0x3f3f3f3f;
    const int mod=1000003;
    
    LL a[maxn], vis[maxn], k;
    
    ///素数打表数组a里面存的就是2到MAXN之间的素数
    void IsPrime()
    {
        k=0;
        for(int i=2; i<maxn; i++)
        {
            ///用数组vis做标记数组
            if(!vis[i])///数组在没有初始化时,默认为都为0,不用初始化数组的原因
            {
                a[k++]=i;
                
                ///i倍数不会是素数标记为1
                for(int j=i+i; j<maxn; j+=i)
                    vis[j]=1;
            }
        }
    }
    
    ///主函数把素数输出看的更明显
    int main()
    {
        IsPrime();
        int n;
        while(~scanf("%d", &n))
        {
            for(int i=0; i<n; i++)
                printf("%lld ", a[i]);
            printf("
    ");
        }
        return 0;
    }
    void Isprime()
    {
        int i, j;
    
        for(i=2; i<N; i++)
        {
            if(v[i]==0)
            {
                a[k++]=i;
    
                for(j=i+i; j<N; j+=i)
                    v[j]=1;
            }
        }
    }
    
    int Judge(long long n)
    {
        int i;
    
        if(n==0 || n==1)return 0;
    
        for(i=0; a[i]*a[i]<=n; i++)
            if(n%a[i]==0)
                return 0;
        return 1;
    }
  • 相关阅读:
    跨域上传文件
    算法
    websocket
    Bottle
    爬虫一
    RabbitMQ
    git&github快速入门
    centos6安装SaltStack
    ajax
    Django之Model操作
  • 原文地址:https://www.cnblogs.com/w-y-1/p/5760136.html
Copyright © 2020-2023  润新知