efficient code for prime number

Revision en1, by tamjedpeace, 2016-03-29 09:16:58

include<bits/stdc++.h>

using namespace std;

bool prime(long long a) { long long b=0,i; for(i=2; i*i<=a; i++) if(a%i==0) return 0; return 1; }

int main() { long long t,m,n; cin>>t; for(long long i=0; i<t; i++) { cin>>n>>m; for(long long j=n; j<=m; j++) { if(prime(j)==1&&j!=1) cout<<j<<endl; } cout <<endl; } return 0; }

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English tamjedpeace 2016-03-29 09:16:58 506 Initial revision (published)