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

luogu_1865 A % B Problem

时间:2017-10-06 13:25:04      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:span   print   pac   ros   ==   turn   ret   cross   std   

#include <cstdio>
#include <iostream>
using namespace std;
const int N=1000000;
int p[N],n,m,nop[N],cnt,sum,ans[N];

int main(){
    scanf("%d%d",&n,&m);
    nop[1]=1;
    for(int i=2;i<=m;i++){
        if(!nop[i]){p[++cnt]=i; sum++;}
        ans[i]=sum;
        for(int j=1;j<=cnt && p[i]<=i && i*p[j]<=m;j++){
            nop[i*p[j]]=1;
            if(i%p[j]==0)break;
        }
    }
    while(n--){
        int l,r;
        scanf("%d%d",&l,&r);
        if(l<1 || r>m){puts("Crossing the line"); continue;}
        printf("%d\n",ans[r]-ans[l-1]);
    }
    return 0;
}

  

 

luogu_1865 A % B Problem

标签:span   print   pac   ros   ==   turn   ret   cross   std   

原文地址:http://www.cnblogs.com/codetogether/p/7631416.html

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