欢迎访问我的新博客: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的更多相关文章

  1. UVa 10110 Light, more light

    开始所有的灯是灭的,不过我们只关心最后一个灯. 在第i次走动时,只有编号为i的倍数的灯的状态才会改变. 也就是说n有偶数个约数的时候,最后一个灯的状态不会改变,也就是灭的. n有奇数个约数的时候也就是 ...

  2. LED Holiday Light -holiday Light Inspection Implementation Recommendations

    China LED Holiday Light Factory & Ninghai County Haohua Electronic Appliance Co., Ltd. pointed o ...

  3. C#Light 和 uLua的对比第二弹

    上次的对比大家还有印象否,C#Light和ulua对比各有胜负 今天我们加入一个去反射优化,这是uLua没办法实现的优化,我们也就只能不要脸的胜之不武了 以原生执行同一测试时间为X1,数字越小的越快 ...

  4. 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 ...

  5. Ambient Light

    [Ambient Light] Ambient light is light that is present all around the scene and doesn’t come from an ...

  6. 精确光源(Punctual Light Sources)

    <Physically-Based Shading Models in Film and Game Production>(SIGGRAPH 2010 Course Notes) (地址: ...

  7. Unity Lighting - Light Types 灯光类型(八)

      Light Types 灯光类型 We have now covered some of the project settings which need to be considered befo ...

  8. 嵊州D3T3 light

    嵊州D3T3 light 光恰似水 兄弟俩曾经 k 次受到过父母的物质激励. 一开始,兄弟俩的能力值为 1,最后,兄弟俩的能力值是 1 + (2 ^k−1)/ n . 当兄弟俩受到价值为 mi 的物质 ...

  9. [币严区块链]ETH搭建节点区块数据同步的三种模式:full、fast、light

    ETH  全节点Archive(归档)模式数据量增长图 上述图表可通过链接查看:https://etherscan.io/chartsync/chainarchive 通过上表,可以看到截止2019年 ...

随机推荐

  1. 从源码看Android中sqlite是怎么读DB的(转)

    执行query 执行SQLiteDatabase类中query系列函数时,只会构造查询信息,不会执行查询. (query的源码追踪路径) 执行move(里面的fillwindow是真正打开文件句柄并分 ...

  2. Java学习之路:ArrayList用法

    1.什么是ArrayList     ArrayList是一个动态数组传奇,使用MSDN声明.那是,Array复杂的版本号,它具有以下优点,例如: 动态的添加和降低元素 实现了ICollection和 ...

  3. C# Windows Schedule task此次收购task下一步执行时间

    最近进行了一次需求和Windows Schedule task相关职能,通过schedule,计算下一次运行task时间. 它用于由第三方DLL实现,以下网站,以下载来自: http://tasksc ...

  4. thinkphp学习笔记2—入口文件

    原文:thinkphp学习笔记2-入口文件 在thinkphp中有两个入口文件,一个是项目的入口文件,是index.php在主目录里面,还有一个是thinkphp框架的的入口文件,放在框架目录下面如: ...

  5. 十天学Linux内核之第一天---内核探索工具类

    原文:十天学Linux内核之第一天---内核探索工具类 寒假闲下来了,可以尽情的做自己喜欢的事情,专心待在实验室里燥起来了,因为大二的时候接触过Linux,只是关于内核方面确实是不好懂,所以十天的时间 ...

  6. 动态传递参数到DevExpress.XtraReports的小结

    原文:动态传递参数到DevExpress.XtraReports的小结 前两种方法和WinForm一样,可以传递参数.数组.实体对象.DataTable等1. 采用构造函数具体用法:在Report中p ...

  7. Codeforces 490F. Treeland Tour 暴力+LIS

    枚举根+dfs 它可以活 , 我不知道有什么解决的办法是积极的 ...... F. Treeland Tour time limit per test 5 seconds memory limit p ...

  8. Android环境结构Android Studio解决方法不能启动,第一次

    android Studio 下载和eclipse 的android开发环境的搭建下载包: 联系: http://pan.baidu.com/s/1kTKJZkN password: qxqf And ...

  9. ClassLoader—流程观察程序执行类加载-verbose:class

    当调试器,有时你需要看到程序加载的类.记忆的恢复情况.本地接口调用,等等..这时候就需要-verbose命令. 在myeclipse能够通过右键设置(例如以下).也能够在命令行输入java -verb ...

  10. crawler_URL编码原理详解

    经常写爬虫的童鞋,难免要处理含有中文的url,大部分时间,都知道url_encode,各个语言也都有支持,今天简单整理下原理,供大家科普 1.特征: 如果URL中含有非ASCII字符的话, 浏览器会对 ...