allia

первые н простых

Nov 5th, 2020 (edited)
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. void eratosfen (int n)
  7. {
  8.   long long *arr = new long long[21474836];
  9.   for (long long p = 0; p < 21474836; p++)
  10.    arr[p] = p;
  11.  
  12.   int index = 0;
  13.  
  14.   for (long long p = 2; p < 21474836 && index < n; p++)
  15.   {
  16.     if (arr[p] != 0)
  17.     {
  18.       index++;
  19.       cout << arr[p] << " ";
  20.       for (long long j = p*p; j < 21474836; j += p)
  21.         arr[j] = 0;
  22.     }
  23.   }
  24. }
  25.  
  26. int main()
  27. {
  28.   int n = 0;
  29.   cin >> n;
  30.  
  31.   eratosfen(n);
  32. }
Add Comment
Please, Sign In to add comment