#CS41008. 阅读程序10-数论8

阅读程序

注意:切勿用电脑直接运行代码得出答案,请用大脑+笔+纸运行代码答题,否则是在浪费你的时间。

第10节:数论

第8题【NOIP】2014

#include <iostream>
using namespace std;
const int SIZE = 100;
int main()
{
    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++;
16      cn = i * 2;
        while ( cn <= n )
        {
            p[cn] = 0;
            cn += i;
        }
    }
    cout << tot << endl;
    return(0);
}

●判断题

(1)n的值为100时程序不会运行错误

(2)被程序的时间复杂度为O(n)

(3)将第16行的cn=i*2改为cn=i,程序输出结果不变

(4)输入30,输出结果为10

●选择题

(5)本程序的功能为

(6)输人100,输出结果为()