在P1217打表,为什么打到 9931399 就没了,程序仍然在运行但不输出任何东西。
#include <iostream>
#include <cmath>
bool is_prime(int x)
{
for (int i = std::sqrt(x); i >= 2; i--)
if (x % i == 0)
return false;
return true;
}
bool is_palindromes(int x)
{
int a = 0, b = x;
while (x != 0)
{
a = a * 10 + (x % 10);
x /= 10;
}
if (a == b)
return true;
return false;
}
int main()
{
// std::freopen("generator.out", "w", stdout);
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
for (int i = 5; i <= 1000000000; i++)
if (is_prime(i) && is_palindromes(i))
std::cout << i << ", ";
return 0;
}