tamjedpeace's blog

By tamjedpeace, history, 8 years ago, In English

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; }

  • Vote: I like it
  • -11
  • Vote: I do not like it

| Write comment?
»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Try the Sieve of Eratosthenes, it'll be a lot faster than the code above. https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes