Hangzhou Electric---2053 Switch Game

Source: Internet
Author: User

Problem Description There is many lamps in a line. All of the themare off at first. A series of operations is carried out on these lamps. On thei-th operation, the lamps whose numbers is the multiple of I change thecondition (on to off and off).

Input Each test case contains only a number n (0< n<= 10^5) in a line.

Output output The condition of the n-th lamp after infinity operations (0-off, 1-on).

Sample Input 1

5

Sample Output 1

0

Hint

Consider the second test case:

The initial condition:0 0 0 0 0 ...

After the first Operation:1 1 1 1 1 ...

After the second Operation:1 0 1 0 1 ...

After the third Operation:1 0 0 0 1 ...

After the fourth Operation:1 0 0 1 1 ...

After the fifth Operation:1 0 0 1 0 ...

The later operations cannot change thecondition of the fifth lamp any more. So the answer is 0.

Author LL

Analysis: This problem just beginning lamp is extinguished, when 1, all is 1 time times the lamp will be bright, when is 2 of time All is twice times the lamp will be extinguished, when is 3 when all the lamp is 3 multiples also will change,,, and so on input a number, must judge whether the lamp is bright or is extinguished, Just determine the number of times the lamp has changed is odd or even, when it is odd, the light is bright, when the even-numbered lights are extinguished

#include <iostream> #include <stdio.h>using namespace Std;int main () {    int n;    while (Cin>>n)    {        int t=0;        for (int i=1;i<=n;i++)        {            if (n%i==0)                t++;        }        if (t%2==0)            cout<<0<<endl;        else            cout<<1<<endl;    }    return 0;}



Hangzhou Electric---2053 Switch Game

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.