60分求助
查看原帖
60分求助
777035
zhangw楼主2022/9/7 21:10
#include <iostream>
#include <cmath>
using namespace std;
int zhishu(int n);
int main()
{
    int x,y=0;
    cin >> x;
    if (x<2)
        cout << '0';
        else if (x>=2&&x<5)
        {
            cout << '2' << endl
                 << '1';
        }
        else{
            cout << '2' << endl
                 << '3' << endl;
            for (int i = 5;; i++)
            {
                if (zhishu(i) == 1)
                {
                    x -= i;
                    if (x<0)
                        break;
                    cout << i << endl;
                    y++;
                }
                if (x<0)
                    break;
    }}
    cout << y+2;
    return 0;
}
int zhishu(int n)
{
    for (int i = 2;i<=(int)sqrt(n);i++)
    if (n%i==0)
        return 0;
    return 1;
}
2022/9/7 21:10
加载中...