zoukankan      html  css  js  c++  java
  • UVa 10110 Light, more light

    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趟,第i趟拔动编号能被i整除的灯的开关,问走过n趟之后,第n盏灯是否是亮的

    其实就是问,n的约数的个数是奇数还是偶数,如果是奇数就拔动奇数次,灯就会是亮的就输出yes,反之如果是偶数就拔动偶数次,灯就会是灭的就输出no

    而n的约数总是成对出现的,也就是说如果p能整除n,那么一定是n=p*q,即p和q成对出现

    所以只有当n是某个数的平方时,即p=q时,n的约数的个数才可能是奇数个,也就是说这道题输入n,只要判断n是不是某个整数的平方即可,如果是就输出yes,不是就输出no

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cmath>
     4 
     5 using namespace std;
     6 
     7 int main()
     8 {
     9     long long n;
    10     while(scanf("%lld",&n)==1&&n)
    11     {
    12         long long t=sqrt(n)+0.5;
    13         if(t*t==n)
    14             puts("yes");
    15         else
    16             puts("no");
    17     }
    18 
    19     return 0;
    20 }
    [C++]
  • 相关阅读:
    在vue中使用 layui框架中的form.render()无效解决办法
    Week03面向对象入门
    Week04面向对象设计与继承
    JAVA暑假作业
    Week02Java基本语法与类库
    201621123082《Java程序设计》第1周学习总结
    利用Asp.net中的AJAX制作网页上自动选取开始日期及结束日期的用户自定义控件
    错误 1 在应用程序级别之外使用注册为 allowDefinition='MachineToApplication' 的节是错误的
    Log4net日志记录、详细配置(自己使用)
    利用队列记录错误日志
  • 原文地址:https://www.cnblogs.com/lzj-0218/p/3531714.html
Copyright © 2011-2022 走看看