SHARE
TWEET

Untitled

a guest Jan 15th, 2020 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int limit = 1e7+7;
  6. vector<bool> prime(limit, true);
  7.  
  8. void sieve(){   // thuat toan sang` nguyen to.
  9.     prime[0] = prime[1] = false;
  10.     for(int i = 2; i < limit ; i++){
  11.         if (prime[i] == false) break;
  12.         for(int j = i*2 ; j < limit ; j += i){
  13.             prime[j] = false;
  14.         }
  15.     }
  16. }
  17.  
  18. int main(){
  19.  
  20.     sieve();
  21.    
  22.     int left , right;
  23.     cin >> left >> right;
  24.     // in ra cac so trong doan [left , right]
  25.     for(int i = left ; i <= right ; i++){
  26.         if (prime[i] == true) cout << i << " ";
  27.     }
  28.  
  29.     return 0;
  30. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top