10110 - Light, more light
来源:互联网 发布:网络名誉权侵权起诉书 编辑:程序博客网 时间:2024/05/15 19:35
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;}
- 10110 - Light, more light
- 10110 - Light, more light
- 10110 - Light, more light
- 10110 - Light, more light
- 10110 - Light, more light
- 10110 - Light, more light
- uva 10110 Light, more light
- uva 10110 - Light, more light
- UvaOJ 10110 - Light, more light
- uva 10110 - Light, more light
- UVa 10110 Light, more light
- UVa 10110 - Light, more light
- UVa 10110-Light, more light
- UVa 10110 - Light, more light
- UVa 10110: Light, more light
- UVA 10110 Light, more light
- uva 10110 - Light, more light
- uva 10110 Light, more light
- Liunx防火墙/etc/sysconfig/iptables 详解
- 张小磊分享:搜索引擎高级搜索指令
- log4j简易入门
- Linux下账户管理操作
- 前方的很远
- 10110 - Light, more light
- 关于NoSQL的思考:为什么我们要优化存储的写性能 .
- 将博客搬至CSDN
- C++拒绝服务攻击DOS
- HDU 2064 汉诺塔III
- J2EE常用jar包作用
- JAVA操作properties文件
- Redis几个认识误区
- iOS应用的真机调试