Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- bool isPNr(int x) {
- int sum = 1 + x;
- for (int d = 2; d <= x / 2; d++) {
- if (x % d == 0) {
- sum += d;
- }
- }
- return sum % 2 == x % 2;
- }
- int kpn(int a, int b, int k) {
- int x;
- for (x = a; x <= b; x++) {
- if (isPNr(x)) {
- k--;
- if (!k) {
- return x;
- }
- }
- }
- return -1;
- }
- int main() {
- cout << kpn(27, 50, 3) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement