tungggg

sang nguyen to

Jan 23rd, 2022 (edited)
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <cmath>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <iostream>
  5. #include <algorithm>
  6. using namespace std;
  7. int a[10000009];
  8. void sieve(){
  9.     for(int i=0;i<10000009;i++){
  10.         a[i]=1;
  11.     }
  12.     a[0]=a[1]=0;
  13.     for(int i=2;i*i<10000009;i++){
  14.         for(int j=i*i;j<10000009;j+=i){
  15.             a[j]=0;
  16.         }
  17.     }
  18. }
  19.  
  20. int main() {
  21.     /* Enter your code here. Read input from STDIN. Print output to STDOUT */  
  22.     unsigned int n;
  23.     cin>>n;
  24.     sieve();
  25.     for(int i=0;i<=n;i++){
  26.         if(a[i]==1){
  27.             cout<<i<<" ";
  28.         }
  29.     }
  30.     return 0;
  31. }
  32.  
Add Comment
Please, Sign In to add comment