2172 - 计算机C13001第一次小组赛C题

通过次数

0

提交次数

0

时间限制 : 2 秒 内存限制 : 128 MB

Ms.Han was addicted to games about light .  

There are N lights putting in a line S[1...N] and we can change their status (open and closed ) by pressing their button. But they have a characteristic, when you press light s[i] (0<=i<=N), those lights who's numbers are i's multiple will also change their status.For example:There are 10 lights s[1...10] whose initial status is closed. When she press the light s[2] (it will be open), then the light s[2],s[4],s[6],s[8] and s[10] will also be open. When she press s[4] again, light s[4] and s[8] will be closed.Now Ms.Han has N lights all closed ,she will press them from 1 to N ,then how many lights will be open in the end?

题目输入

The input will contain multiple test cases ,Each case will only contain a number N(1 <= N <= 1,000,00).

题目输出

A integer on a single line for each case indicates the number of lights which are open in the end.

输入/输出样例

输入格式

10
15
20

输出格式

3
3
4

C语言解答

#include<stdio.h>
void main()
{
	int N,i,count=0;
    while (scanf("%d",&N)!=EOF)
	{	
		for(i=1;i<=N;i++)
	{	
    	
		if(i*i<=N)
		count+=1;
		else
		break;	
}printf("%d\n",count);
		count=0;
	}

}




C++解答

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{

    int a;
    while(scanf("%d",&a)!=EOF)
    {
        int b=sqrt(a);
       cout<<b<<endl;

    }
    return 0;
}