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
题意:有n盏灯,编号从1~n,进行n次操作,在进行i次操作的时候调整i的倍数的灯的编号(将关变成开,将开变成关),刚开始所有的灯都是关闭状态,问第n盏灯最后是什么状态。
解题思路:若n的约数的个数是奇数,那么是打开状态(即输出1),如果是偶数,输出 0,是关闭状态。
代码:
#include <stdio.h>
int main()
{
int n,i,sum;
while(scanf("%d",&n)!=EOF)
{
sum=0;
for(i=1;i<=n;i++)
{
if(n%i==0)
sum++;
}
printf("%d\n",sum%2);
}
return 0;
}