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年 ...
随机推荐
- Codeforces 374D Inna and Sequence 二分法+树状数组
主题链接:点击打开链接 特定n一个操作,m长序列a 下列n的数量 if(co>=0)向字符串加入一个co (開始是空字符串) else 删除字符串中有a的下标的字符 直接在序列上搞.简单模拟 # ...
- Javascript学习5 - 函数
原文:Javascript学习5 - 函数 在Javascript中,函数和对象是交织在一起的.有些函数的特性与对象相关联.这一点的内容在第六部分会讨论到. 这一部分主要讨论函数与其它比较熟悉的语言( ...
- Nyoj 一笔画问题(图论)
描述 zyc从小就比较喜欢玩一些小游戏,其中就包括画一笔画,他想请你帮他写一个程序,判断一个图是否能够用一笔画下来. 规定,所有的边都只能画一次,不能重复画. 输入 第一行只有一个正整数N(N&l ...
- Python的print中国输出对齐问题
问题叙述性说明: 在使用Python内置函数print当输出英语,应用格输出类型可以对齐很好: s1 = 'I am a long sentence.' s2 = 'I\'m short.' prin ...
- 求解决!!!SystemVerilog于ModelSim在编译和执行
我们正在学习SV流程,样品执行书.. 功能:函数返回数组. Code1: /*书上提供的样例.存在错误,不可执行 function void init(ref int f[5], int start) ...
- 【百度地图API】手机浏览器抓包工具及其使用方法
原文:[百度地图API]手机浏览器抓包工具及其使用方法 摘要:为了测试地图API在手机浏览器上的性能,需要给手机浏览器设置代理.通过代理,我们可以在PC上获取到抓包数据.进而对性能做进一步分析. -- ...
- 【.NET特供-第三季】ASP.NET MVC系列:MVC与三层图形对照
近期在开发小组在研究:BS项目中是利用'MVC框架'还是继续沿用'三层'的问题. 由于曾经的.NET项目大多数都是利用三层开发的,所以大多数人都可以对三层进行熟练地运用.而项目的開始我们也曾听说过MV ...
- BAT 特殊符号总结
原文:BAT 特殊符号总结 BAT特殊符号总结,用好特殊符号,利用提高开发效率.^ 转义符 用在特殊符号之前 比如: echo 非常^&批处理 如果不加^ 那么"批处理"将 ...
- 修改vim/terminal配色
http://blog.csdn.net/angle_birds/article/details/11694325
- C# .NET ASP.NET 其中关系你了解多少
有些人一直在做这方面..但突然有人来问你这些问题..估计有很多答不上来. 1..NET是一个平台,一个抽象的平台的概念. .NET平台其本身实现的方式其实还是库,抽象层面上来看是一个平台. 个人理解. ...