Light, more light - PC110701
欢迎访问我的新博客:http://www.milkcu.com/blog/
原文地址:http://www.milkcu.com/blog/archives/uva10110.html
原创:Light, more light - PC110701
作者:MilkCu
题目描述
| 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
Sadi Khan
Suman Mahbub
01-04-2001
解题思路
任一整数,它可能为平方数或非平方数。
若为非平方数,则它的因子总是成对出现的,即因子个数为偶数;
若为平方数,则它的因子个数为奇数。
也就是说:
如果n为非平方数,则灯的状态为关;
如果n为平方数,则灯的状态为开。
刚开始评测一直说是错误的答案,可能是因为数据类型和头文件的问题。
代码实现
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main(void) {
while(1) {
long long n;
cin >> n;
if(n == 0) {
break;
}
long long tmp = sqrt(n);
if(n == tmp * tmp) {
cout << "yes" << endl;
} else {
cout << "no" << endl;
}
}
return 0;
}
(全文完)
本文地址:http://blog.csdn.net/milkcu/article/details/23543557
Light, more light - PC110701的更多相关文章
- UVa 10110 Light, more light
开始所有的灯是灭的,不过我们只关心最后一个灯. 在第i次走动时,只有编号为i的倍数的灯的状态才会改变. 也就是说n有偶数个约数的时候,最后一个灯的状态不会改变,也就是灭的. n有奇数个约数的时候也就是 ...
- LED Holiday Light -holiday Light Inspection Implementation Recommendations
China LED Holiday Light Factory & Ninghai County Haohua Electronic Appliance Co., Ltd. pointed o ...
- C#Light 和 uLua的对比第二弹
上次的对比大家还有印象否,C#Light和ulua对比各有胜负 今天我们加入一个去反射优化,这是uLua没办法实现的优化,我们也就只能不要脸的胜之不武了 以原生执行同一测试时间为X1,数字越小的越快 ...
- How to Pronounce the Idiom: ‘Out Like a Light’
How to Pronounce the Idiom: ‘Out Like a Light’ Share Tweet Share Tagged With: Idioms English is full ...
- Ambient Light
[Ambient Light] Ambient light is light that is present all around the scene and doesn’t come from an ...
- 精确光源(Punctual Light Sources)
<Physically-Based Shading Models in Film and Game Production>(SIGGRAPH 2010 Course Notes) (地址: ...
- Unity Lighting - Light Types 灯光类型(八)
Light Types 灯光类型 We have now covered some of the project settings which need to be considered befo ...
- 嵊州D3T3 light
嵊州D3T3 light 光恰似水 兄弟俩曾经 k 次受到过父母的物质激励. 一开始,兄弟俩的能力值为 1,最后,兄弟俩的能力值是 1 + (2 ^k−1)/ n . 当兄弟俩受到价值为 mi 的物质 ...
- [币严区块链]ETH搭建节点区块数据同步的三种模式:full、fast、light
ETH 全节点Archive(归档)模式数据量增长图 上述图表可通过链接查看:https://etherscan.io/chartsync/chainarchive 通过上表,可以看到截止2019年 ...
随机推荐
- OCP读书笔记(24) - 题库(ExamD)
327.You have a database with the following tablespaces: SYSTEM, SYSAUX, UNDO, USERS, TEMP.You want t ...
- 配置主机路由表(route)(两)
我们谈到了路由在互联网为基础的时间问题,必须有一个路径之间的两个主机可通信 TCP/IP 合约,否则就不能是有线啊! 一般来说.只要有一个网络接口,的接口将产生的路由.例如,在哥斯达黎加的内部主机鸟有 ...
- hdu Simpsons’Hidden Talents(kmp)
Problem Description Homer: Marge, I just figured out a way to discover some of the talents we weren’ ...
- Android中的“再按一次返回键退出程序”实现[转]
用户退出应用前给出一个提示是很有必要的,因为可能是用户并不真的想退出,而只是一不小心按下了返回键,大部分应用的做法是在应用退出去前给出一个Dialog,我觉得这样不太友好,用户还得移动手指去按dial ...
- Handler详细说明系列(六)——View的post()详解
MainActivity例如下列: package cc.testui2; import android.os.Bundle; import android.view.View; import and ...
- Android有效的治疗方法Bitmap,减少内存
Android有效的治疗方法Bitmap,减少内存 照片可能有不同的大小. 在很多情况下,大小.比如,我们的Camera应用,我们所拍的照片的大小远大于屏幕显示的大小 假如你的应用被限制了内存使用,显 ...
- Postman 是一个非常棒的Chrome扩展,提供功能强大的API & HTTP 请求调试
Postman 是一个非常棒的Chrome扩展,提供功能强大的API & HTTP 请求调试 需要FQ才能安装,使用时应该不用FQ了,除非使用postman的历史记录功能: 非常棒的C ...
- Jquery()核心函数的7个重载方法
(1) jquery() 该函数返回一个空的jQuery对象.在jQuery1.4以后的版本中,改函数返回一个空的jQuery对象.在之后的版本中,该函数会返回一个包含document节点的对象. ( ...
- android 反编译(dex 和 odex),非脑残转帖,绝对可靠
Android 反编译 反编译odex文件(比如framework.odex),若是反编译dex,直接第4步 1.因为反编译odex的工具在D:\Develop tools\android反编译工具\ ...
- 湘潭oj1203/邀请赛A称号 数论+java睑板
乞讨 n%1+n%2+n%3+n%4+.........n%n=,n<=10^12次要. 一味的找规律之初.没有发现.后来,前辈执教后,人才平淡,所以,现在唯一明确的. 首先在地图上: 对于该题 ...