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年 ...
随机推荐
- robot framework-databaselibaray库使用(python)(转)
公司做项目用到了databaselibaray,刚开始使用时碰到了很多问题,网上也查阅了很多资料终于是可以用了,现在整理记录下来,有需要的同学可随意使用: 另,本文主要是databaselibaray ...
- easyUI 插件写法 ---Validatebox 插件为例
easyui 的每个组件都有属性.方法和事件.用户可以很容易地对这些组件进行扩展. js地址:jquery-easyui-1.3.3/jeasyui-extensions/jeasyui.extens ...
- Javascript学习3 - 语句
原文:Javascript学习3 - 语句 javascript语句同C/C++语句相似,但也几个特殊的语句,在C/C++中没在碰到,列举在下面. 3.1 for/in 语句 可以用来遍历对象 ...
- this、访问修饰符——Java笔记(五)
this 表示当前对象 谁调用方法谁就是当前对象 用static修饰的代码块里面不能使用this 方法里面有一个和字段同名的局部变量时,不能省略this this还 ...
- 浅谈 js 正则字面量 与 new RegExp 执行效率
原文:浅谈 js 正则字面量 与 new RegExp 执行效率 前几天谈了正则匹配 js 字符串的问题:<js 正则学习小记之匹配字符串> 和 <js 正则学习小记之匹配字符串优化 ...
- NYoj 最舒适的路线
题目链接:http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=711 分析:枚举速度最大的边,找出能够从S到达T的最大速度,然后求出它们的比值,与已 ...
- CSDN专家吐槽实录
今天打开CSDN发现界面上的几个图标发生了变化,一个小小的变化,却引起了诸多CSDN专家对CSDN社区未来发展的思考,我特意从群里讲对话黏贴出来,希望各位能给予积极评价和建议. 你已经是群成员了,和大 ...
- Socket 由浅入深系列--------- 简单实现编程(三)
socket 由浅入深 原理(一)介绍了一些,以下也就是简单实现,并未考虑其它性能化! 使用TCP的server客户机举例 server 设置一个简单的TCPserver涉及下列步骤: 调用 sock ...
- style中position的属性值具体解释
Position的英文原意是指位置.职位.状态.也有安置的意思.在CSS布局中,Position发挥着非常关键的数据,非常多容器的定位是用Position来完毕. Position属性有四个可选值,它 ...
- javascritpt 原型链
// 基类 var BaseCalculator = function(){ this.decimalDigits = 2; }; // public BaseCalculator.prototype ...