时间限制 | 1000ms | 空间限制 | 131072K |
题目:
Johnson和Nancy要在星光下吃晚餐。这是一件很浪漫的事情。
为了增加星光晚餐那浪漫的氛围,他拿出了一个神奇的魔法棒,并且可以按照一定的规则,改变天上星星的亮暗。
Johnson想考考Nancy,在他挥动魔法棒后,会有多少颗星星依旧闪耀在天空。他知道,Nancy一定会一口说出答案。
Nancy当然知道怎么做啦,但她想考考你!
Johnson先将天上n个星星排成一排,起初它们都是暗的。
他告诉他的妹子,他将挥动n次魔法棒,第i次挥动会将编号为i的正整数倍的星星的亮暗反转,即亮的星星转暗,暗的星星转亮。
Johnson想问Nancy,最终会有多少个星星依旧闪亮在天空。
输入:
一个整数n,含义请见题目描述。
输出:
一个整数ans,即n次操作后会有多少个星星依旧闪亮。
样例输入:
3
样例输出:
1
样例输入:
7
样例输出:
2
备注:
对于60%的数据:n≤2×106
对于100%的数据:n≤1018
题意:天上有n颗星星最开始都是暗的,他有一个魔法棒,可以挥动n次,第i次可以让i以及i的倍数的星星状态相反,问最后还亮着的星星有多少。
思路:写几个找规律就可以了,最后还亮着的灯就是n开根号向下取整。
AC代码:
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long ll;
int main()
{
double n;
while(scanf("%lf",&n)!=EOF)
{
int k=sqrt(n);
printf("%d
",k);
}
}