egogoboy

постулат бертрана

May 15th, 2022
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <cmath>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. bool check(int& x) {
  9.  
  10.     for (int i = 3; i < x / 2; i+=2) {
  11.         if (x % i == 0) {
  12.             return false;
  13.         }
  14.     }
  15.  
  16.     return true;
  17.  
  18. }
  19.  
  20. int main() {
  21.  
  22.     int n;
  23.     cin >> n;
  24.  
  25.     int temp = 0, i = 0;
  26.  
  27.     if (n % 2 == 0) {
  28.         i = n + 1;
  29.     }
  30.     else {
  31.         i = n + 2;
  32.     }
  33.     for (i; i < 2 * n; i+=2) {
  34.  
  35.         if (check(i))
  36.             temp++;
  37.  
  38.     }
  39.     cout << temp << endl;
  40.  
  41.    
  42. }
Advertisement
Add Comment
Please, Sign In to add comment