Prime Generator problem Spoj Solution

 #include<iostream>

#include<cmath>

using namespace std;

typedef long long l;

bool prime(l );

int main(){

l t;

cin>>t;

while(t--){

l n,m,i;

cin>>m>>n;

for(i=m;i<=n;i++){

  if(prime(i)){

cout<<i<<endl;

}

}

cout<<endl;

}

}

bool prime(l a){

if(a==1)

return 0;

for(l i=2;i*i<=a;i++){

if(a%i==0)

return 0;

}

return 1;

}


Comments

Popular posts from this blog

Factorials problem spoj Solution

Adding Reversed Numbers Spoj Solutions