杭电2053

Re:题意:有无限多的电灯排成一列,一开始都是关,操作无限多次,第i次操作会把编号为i和i的倍数的电灯改变状态。问最后第i盏电灯的状态是开还是关    //后边有数据。。。
#include<stdio.h>
int main()
{
    int a,b,i;
    while(scanf("%d",&a)!=EOF)
    {
        b=0;
        for(i=1;i<=a;i++)
        {
            if(a%i==0)
            b++;
        }
        if(b%2==1)//开关变化(1 0 1 0 1 0.......);
        printf("1
");
        else
        printf("0
");
    }
    return 0;
}
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.
原文地址:https://www.cnblogs.com/soTired/p/4415128.html