Here is the code.
'#include #include using namespace std; typedef unsigned long int u64; int main() { u64 m,n,i,p,j; int t; cin>>t; while(t--) { cin>>m>>n; unsigned long int* a=new unsigned long int[100001]; //initialization a[0]=0; a[1]=0; for(i=2;i<100000;i++) { a[i]=i; } for(p=2;p<=sqrt(n);p++) //Sieve to find prime numbers { if(a[p]!=0) { j=p*p; while(j<=n) { a[j]=0; j=j+p; } } } for(p=m;p<=n;p++) { if(a[p]!=0) { cout<
Here implemented the sieve but its showing segmented fault. In SPOJ its giving this error. Please suggest me any corrections to be made.
Aucun commentaire:
Enregistrer un commentaire