10110 - Light, more light

来源:互联网 发布:网络名誉权侵权起诉书 编辑:程序博客网 时间:2024/05/15 19:35
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

3624181910

Sample Output

noyesno

题意 :有n盏灯,一开始全部关闭。然后从左往右走N趟,第 i 趟按一下序号为 i 的倍数的灯的开关。问走完之后,最后一盏灯是否开着。

一开始打算暴力,一看数据很大。放弃了。后来仔细一想,由于n如果能被k整除,那么n肯定也可以被(n/k)整除,所以是成对出现的。只有n是完全平方数,才会多出来一个。

第一次给wa了。主要是没有考虑到数据范围,int类型最大值是2^31-1..而unsigned类型才是2^32。

#include<iostream>#include<cstdio>#include<cstring>#include<cmath>using namespace std;int main (){    long long n,t;    while(cin>>n)    {        if (n==0) break;        t=sqrt(n*1.0);        if (t*t==n) cout<<"yes"<<endl;        else cout<<"no"<<endl;    }    return 0;}


原创粉丝点击