UVa 10110 Light, more Light: number theory

Source: Internet
Author: User
Tags switches time limit

10110-light, more Light

Time limit:3.000 seconds

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=100&page=show_ problem&problem=1051

The Problem
There is mans 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. This is, if it's pressed then the bulb turns on. Another Press would turn it off. To the Save power consumption (or May are he mad or something else) he does a peculiar thing. If in a corridor there are ' n ' bulbs, he walks along the corridor of the ' n ' Times and ' i ' th forth The switches whose serial is divisable by I. He does is not the 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 are have to determine what are the final condition of the last bulb. Is it in or off?

The Input
The input would 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 are should not process this input.
The Output
Output "Yes" if the light is on otherwise "no" and "a single".
Sample Input

3
6241
8191
0

Sample Output

No
Yes
No

Notice that all the bulbs are off at first.

Simplification: We only need to compute the parity of the number of I (that is, the number of n factors) that satisfies the i|n.

Note that when n is not a full square, n=a*b a must not be equal to B, at which point N has an even number of factors.

Conversely, when N is a full square number, n must have an odd number of factors.

Complete code:

/*0.039s*/
    
#include <cstdio>  
#include <cmath>  
    
int main ()  
{  
    unsigned int n;///Note data range  
    int m;  
    while (scanf ("%d", &n), N)  
    {  
        m = (int) sqrt (n);  
        Puts (M * m = = n? "Yes": "no");  
    return 0;  
}

See more highlights of this column: http://www.bianceng.cn/Programming/sjjg/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.