Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
【小心】 数据可能全是负的 所以要坐一个处理#include <iostream> #include <stdio.h> using namespace std; const int mm=100002; bool su[100005]={0}; int a[mm]={0}; void makesu()//做素数表 { int i,j,k,m; for(i=2;i<=mm/2;i++) if(!su[i]) { k=i*2; while(k<=mm) su[k]=true,k+=i; } for(i=2;i<=mm-2;i++) if(!su[i]) a[i]=a[i-1]+1; else a[i]=a[i-1]; //存放0~i的素数 } int main() { int l,r; makesu(); scanf("%d%d",&l,&r); while(!(l==-1&&r==-1)) { l=max(l,1);//小心此处【关键处理】 r=max(r,1);//小心此处【关键处理】 printf("%d\n",a[r]-a[l-1]); scanf("%d%d",&l,&r); } // cout << "Hello world!" << endl; return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator