码迷,mamicode.com
首页 > 其他好文 > 详细

素数筛 E - Fermat’s Chirstmas Theorem

时间:2014-08-05 18:39:19      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   io   for   div   amp   

#include <iostream>
#include <stdio.h>
#include <math.h>
#include <vector>

using namespace std;
int a[1000001];
int  prime[1000001];
int main()
{
    int k,tt=0;
    int p;
    a[0]=a[1]=0;
    a[2]=1;
    for(int i=3;i<=1000000;i++)
    {
        a[i]=i%2==0?0:1;
    }
    int t=(int )sqrt(1000000*1.0);
    for(int j=3;j<=t;j++)
    {
        if(a[j])
        {
            for(int i=j*j;i<1000000;i=i+2*j)
              a[i]=0;
        }
    }
    for(int i=1;i<100;i++)
    {
        if(a[i]) printf("%d ",i);
    }
    for(int i=2;i<=1000000;i++)
    {
        if(a[i])
        prime[tt++]=i;
    }
    int L,U;
    int  i;
    while(scanf("%d%d",&L,&U))
    {
        k = 0;
        p = 0;
        if(L == -1 && U == -1)
        break;
        for(i=0;i<tt;i++)
        {
            if(prime[i]>=L&&prime[i]<=U)
            {
                k++;
                if((prime[i]-1)%4==0)
                p++;
            }
        }
        if(L<=2&&U>=2) p++;
        printf("%d %d %d %d\n",L,U,k,p);
    }
}

 

素数筛 E - Fermat’s Chirstmas Theorem,布布扣,bubuko.com

素数筛 E - Fermat’s Chirstmas Theorem

标签:style   blog   color   os   io   for   div   amp   

原文地址:http://www.cnblogs.com/yangyongqian/p/3892528.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!