Problem Description
There are many lamps in a line. All of them are off at first. A series of operations are carried out on these lamps. On the i-th operation, the lamps whose numbers are the multiple of i change the condition ( on to off and off to on ).
Input
Each test case contains only a number n ( 0< n<= 10^5) in a line.
Output
Output the condition of the n-th lamp after infinity operations ( 0 - off, 1 - on ).
Sample Input
1
5
Sample Output
1
0
Hint
Consider the second test case:
The initial condition : 0 0 0 0 0 …
After the first operation : 1 1 1 1 1 …
After the second operation : 1 0 1 0 1 …
After the third operation : 1 0 0 0 1 …
After the fourth operation : 1 0 0 1 1 …
After the fifth operation : 1 0 0 1 0 …
The later operations cannot change the condition of the fifth lamp any more. So the answer is 0.
思路
可以模拟过好像。。。
话说这道题我的不知道怎么分类。。。
题意:给你n个灯,刚开始全灭,问经过无穷多次操作后,第n个灯状态
对于第i次操作,改变所有i的倍数的状态
发现当操作到n+1次之后肯定不会对n有影响,此题变为操作n次之后的n的状态
下面分析:刚开始n的状态为0,如果对第n个灯操作了偶数次,其状态还是0,
操作奇数次变为1,现在来分析对于n:如果i是n的约数,就会改变n的状态,但是
j=n/i也是n的约数,还会把n的状态改变回来,到这里可以发现当i=n/i的时候,才会
对n的状态发生影响,刚开始n状态为0,如果n是个完全平方数,则会变为1.
代码
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
int n,k;
int main()
{
while(scanf("%d",&n)!=EOF)
{
k=(int)sqrt(n)+0.5;
if (k*k==n) printf("1\n");
else printf("0\n");
}
return 0;
}
短到不行