1. 程式人生 > >luogu_1865 A % B Problem

luogu_1865 A % B Problem

|| nop pan span printf using blog pri const

#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