#10749. 数论第八题(NOIP2014)

数论第八题(NOIP2014)

第八题(NOIP2014)

#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++;
        cn=i*2;
        while(cn<=n){
            p[cn]=0;
            cn+=i;
        }
    }
    cout<<tot<<endl;
    return 0;
}
  1. 【判断题】n的值为100时程序不会运行错误。
    {{ select(1) }}
  • 正确
  • 错误
  1. 【判断题】该程序的时间复杂度为O(n)。
    {{ select(2) }}
  • 正确
  • 错误
  1. 【判断题】将第12行的 cn=i * 2 改为 cn=i ,程序输出结果不变。
    {{ select(3) }}
  • 正确
  • 错误
  1. 【判断题】输入30,输出结果为10。
    {{ select(4) }}
  • 正确
  • 错误
  1. 【选择题】本程序的功能为( )。
    {{ select(5) }}
  • 求n以内的质数
  • 求n以内与n互质的数
  • 求n的约数
  • 求n以内与n不互质的数
  1. 【选择题】输入100,输出结果为( )。
    {{ select(6) }}
  • 24
  • 22
  • 25
  • 23