10110-light, more Light
Time limit:3.000 seconds
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=100&page=show_ problem&problem=1051
The Problem
There is mans 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. This is, if it's pressed then the bulb turns on. Another Press would turn it off. To the Save power consumption (or May are he mad or something else) he does a peculiar thing. If in a corridor there are ' n ' bulbs, he walks along the corridor of the ' n ' Times and ' i ' th forth The switches whose serial is divisable by I. He does is not the 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 are have to determine what are the final condition of the last bulb. Is it in or off?
The Input
The input would 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 are should not process this input.
The Output
Output "Yes" if the light is on otherwise "no" and "a single".
Sample Input
3
6241
8191
0
Sample Output
No
Yes
No
Notice that all the bulbs are off at first.
Simplification: We only need to compute the parity of the number of I (that is, the number of n factors) that satisfies the i|n.
Note that when n is not a full square, n=a*b a must not be equal to B, at which point N has an even number of factors.
Conversely, when N is a full square number, n must have an odd number of factors.
Complete code:
/*0.039s*/
#include <cstdio>
#include <cmath>
int main ()
{
unsigned int n;///Note data range
int m;
while (scanf ("%d", &n), N)
{
m = (int) sqrt (n);
Puts (M * m = = n? "Yes": "no");
return 0;
}
See more highlights of this column: http://www.bianceng.cn/Programming/sjjg/