打表失败求助
  • 板块灌水区
  • 楼主lzy20091001
  • 当前回复4
  • 已保存回复4
  • 发布时间2023/11/25 17:12
  • 上次更新2023/11/25 18:47:47
查看原帖
打表失败求助
932039
lzy20091001楼主2023/11/25 17:12

在P1217打表,为什么打到 99313999931399 就没了,程序仍然在运行但不输出任何东西。

#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;
}

2023/11/25 17:12
加载中...