Код: Выделить всё
#include
using namespace std;
int nextprime (int);
bool primality (int);
int main () {
int a;
cin >> a;
bool prime = primality(a);
while (prime) {
cout a;
prime = primality(a);
}
}
int nextprime (int x) {
++x;
if (x % 2 == 0 and x != 2) ++x;
bool prime = primality(x);
while (not prime) {
x = x + 2;
prime = primality (x);
}
return x;
}
bool primality (int x) {
if (x % 2 == 0 and x != 2) return false;
for (int number = 3; number*number
Подробнее здесь: [url]https://stackoverflow.com/questions/79090826/finding-next-prime-number-lands-in-an-execution-error-time-limit-exceeded[/url]