Re:题意:有无限多的电灯排成一列,一开始都是关,操作无限多次,第i次操作会把编号为i和i的倍数的电灯改变状态。问最后第i盏电灯的状态是开还是关 //后边有数据。。。
#include<stdio.h> int main() { int b,n,i; while(scanf("%d",&n)!=EOF) { if(n==1)//第一次操作,开关全变为1; printf("1\n"); else { b=0; for(i=2;i<=n;i++)//从2开始判断约数,开关从1开始; { if(n%i==0) b++; } if(b%2==0)//判断开关变化次数,(1 0 1 0 1 0........); printf("1\n"); else printf("0\n"); } } 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.
时间: 2024-11-12 13:34:43