首页 > 代码库 > Light, more light UVA 10110

Light, more light UVA 10110

说说:题意大概就是给定一个数n,然后从1遍历到n,原本要输出的状态是no,然后再遍历过程中遇到n的因子就变一次状态。最后将最终的状态输出。解法的话,将这个过程模拟一遍也是可以的。但我们知道若n能被m整出,那么也必定能被n/m整除,所以若n不是平方数的话状态肯定变换偶数次。照这个思路,代码的效率也就提高不少啦~


题目:

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

一个叫"mabu"的人是专门负责开关我们学校的灯的。他现在要开关一条走廊的灯。每个灯泡都有自己的开关,

 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‘

他做了一件非常奇怪的事。如果走廊里有‘n’盏灯,他沿着走廊来回走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

并且在第i次的时候只按序号能被i整除的灯泡的开关。他在回到他最初位置的过程中不按开关

 initial position. A i‘th walk is defined as going down the corridor (while doing the peculiar thing) and coming back again.

第i次行走的意思是沿着走廊走过去(同时做上述奇怪的事)然后再走回来。

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.

输入是一个整数,代表走廊上的第n盏灯。n小于等于2^32-1.输入为0代表输入结束,此时你无需输出

 You should not process this input.

The Output

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

灯亮输出“yes”,否则输出“no”

Sample Input

3
6241
8191
0

Sample Output

no
yes
no

源代码:

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

int main(){
 double n;
 freopen("input.txt","r",stdin);
 while(scanf("%lf",&n)){
    if(n==0)
        break;

    if(sqrt(n)==(unsigned)sqrt(n))//判断是否为平方数
        printf("yes\n");
    else
        printf("no\n");
 }
 return 0;
}