Advertisement
STANAANDREY

BAC 4/19*/2022 4

Apr 19th, 2022
834
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. bool isPNr(int x) {
  5.     int sum = 1 + x;
  6.     for (int d = 2; d <= x / 2; d++) {
  7.         if (x % d == 0) {
  8.             sum += d;
  9.         }
  10.     }
  11.     return sum % 2 == x % 2;
  12. }
  13.  
  14. int kpn(int a, int b, int k) {
  15.     int x;
  16.     for (x = a; x <= b; x++) {
  17.         if (isPNr(x)) {
  18.             k--;
  19.             if (!k) {
  20.                 return x;
  21.             }
  22.         }
  23.     }
  24.     return -1;
  25. }
  26.  
  27. int main() {
  28.     cout << kpn(27, 50, 3) << endl;
  29.     return 0;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement