Advertisement
sajid161

Class - 26 : Task - 1

Jan 18th, 2025
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int mx=1e8+123;
  4. bool is_prime[mx];
  5. vector<int>v;
  6. void prime_gen(int n)
  7. {
  8.     for(int i=3;i*i<=n;i+=2)
  9.     {
  10.         if(is_prime[i]==0)
  11.         {
  12.             for(int j=i*i;j<=n;j+=(i+i))
  13.             {
  14.                 is_prime[j]=1;
  15.             }
  16.         }
  17.     }
  18.     v.push_back(2);
  19.     for(int i=3;i<=n;i+=2)
  20.     {
  21.         if(is_prime[i]==0) v.push_back(i);
  22.     }
  23. }
  24. int main()
  25. {
  26.     prime_gen(100000000);
  27.     for(int i=0;i<v.size();i+=100)
  28.     {
  29.         cout<<v[i]<<endl;
  30.     }
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement