Sreekar_0125

Untitled

Jul 5th, 2022
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. #define max 1000000000
  5. #define ll long long int
  6. bool a[1000000002];
  7.  
  8. void compute() {
  9.     memset(a,true,sizeof(a));
  10.     a[1]=false;
  11.     for(ll i=2;i<=sqrt(max);i++) {
  12.         for(ll j=i*i;j<=max;j+=i) {
  13.             a[j]=false;
  14.         }
  15.     }
  16. }
  17. int main() {
  18.     ios_base::sync_with_stdio(false);
  19.     cin.tie(NULL); cout.tie(NULL);
  20.     int t;
  21.     cin >> t;
  22.     compute();
  23.     while(t--) {
  24.         ll n1,n2;
  25.         cin>>n1>>n2;
  26.        
  27.         for(ll i=n1;i<=n2;i++) {
  28.             if(a[i]) cout << i << endl;
  29.         }
  30.         cout << endl;
  31.     }
  32.     return 0;
  33. }
  34.  
  35.  
Advertisement
Add Comment
Please, Sign In to add comment