uva 10110 Light, more light(因子的特性)

Light, more light

The Problem

There is man named "mabu" for switching on-off light in our University. He switches on-off the lights in a corridor. Every bulb has its own toggle switch. That is, if it is pressed then the bulb turns on. Another press will turn it off. To save power consumption (or may be he is mad or something else) he does a peculiar thing. If in a corridor there is `n' bulbs, he walks along the corridor back and forth `n' times and in i'th walk he toggles only the switches whose serial is divisable by i. He does not press any switch when coming back to his initial position. A i'th walk is defined as going down the corridor (while doing the peculiar thing) and coming back again.

Now you have to determine what is the final condition of the last bulb. Is it on or off? 
 

The Input

The input will be an integer indicating the n'th bulb in a corridor. Which is less then or equals 2^32-1. A zero indicates the end of input. You should not process this input.

The Output

Output " yes " if the light is on otherwise " no " , in a single line.

Sample Input

3
6241
8191
0

Sample Output

no
yes
no
题目大意:走廊里有N盏灯,初始状态为关,有个脑残,走了有m次,(m为N的因子数),第i次走时,碰到当前第i个因子的倍数时,就改变当前灯的状态,问最后一盏灯在脑残走完之后的状态。

解题思路:模拟会超时,题目可以简单理解成判断N是否为完全平方数,因为因子都是成对出现的,当N为完全平方数时,t * t = N ,则N的因数中有两个时相同的,因子的个数即为奇数,灯为开。

#include<stdio.h>
#include<math.h>

int main(){
	long long n, m;
	while (scanf("%lld", &n), n){
		m = (long long)sqrt(double(n));
		if (m * m == n)
			printf("yes\n");
		else
			printf("no\n");
	}
	return 0;
}

你可能感兴趣的:(uva 10110 Light, more light(因子的特性))