#include using namespace std;

bool prime(int n) { if (n <= 1) { return false; }

for (int i = 2; i * i <= n; i++)
{
    if (n % i == 0)
    {
        return false;
    }
}

return true;

}

int main() { int x; cin >> x;

for (int i = 2; i <= x; i++)
{
    if (prime(i))
    {
        cout << i << ' ';
    }
}

return 0;

}

C++ 判断素数并输出指定范围内所有素数

原文地址: https://www.cveoy.top/t/topic/qe5B 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录