#include<stdio.h>
int a[2000003];
int b[2000003];
int s[2000003];
const int p=2000000;
/*
5
1 10
1 100
1 1000
1 10000
1 100000
*/
int main()
{for(int i=2;i*i<=p;i++){if(a[i]==0){for(int j=i*i;j<=p;j+=i) a[j]=1;//标记为合数; }}int temp=0,flag=0;for(int i=3;i<=p;i++){if(a[i]==0&&flag<1) {flag++;temp=i;continue;}if(a[i]==0){if(a[(i+temp)/2]==1) b[(i+temp)/2]=1;temp=i;}} for(int i=1;i<=p;i++) s[i]=s[i-1]+b[i];int k,x,y;scanf("%d",&k);while(k--){int abc=0,bcd=0;scanf("%d %d",&x,&y);printf("%d\n",s[y]-s[x-1]);}return 0;
}
详细解决方案
XTU OJ 1339 Interprime
热度:15 发布时间:2023-12-04 21:56:39.0