首页 > 试题广场 >

#include using names...

[填空题]
#include <iostream>
using namespace std;
const int SIZE = 100;
int main(void)
{
    int p[SIZE];
    int n, tot, i, cn;
    tot = 0;
    cin >> n;
    for (i = 1; i <= n; i++)
    p[i] = 1;
    for (i = 2; i <= n; i++){
        if (p[i] == 1)
            tot++;
        cn = i * 2;
        while (cn <= n) {
            p[cn] = 0;
            cn += i;
        }
    }
    cout << tot << endl;
    return 0;
}
输入:30
输出:1

这道题你会答吗?花几分钟告诉大家答案吧!