HDU2053. Java

Source: Internet
Author: User

Switch Game

Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 14821 Accepted Submission (s): 9051


Problem Descriptionthere is many lamps in a line. All of them is off at first. A series of operations is carried out on these lamps. On the i-th operation, the lamps whose numbers is the multiple of I, the condition (on to off and off to on).

Inputeach test case contains only a number n (0< n<= 10^5) on a line.

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

Sample Input15

Sample Output10HintHintconsider 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 the condition of the fifth lamp any more. So the answer is 0.

Import java.util.*;
Class main{
public static void Main (String args[])
{Scanner cin=new Scanner (system.in);
while (Cin.hasnext ())
{int n=cin.nextint ();
if (n==1)
System.out.println ("1");
else{
int sum=1;
for (int i=2;i*i<=n;i++)
{if (n%i==0&&i!=n/i)
sum+=2;
else if (n%i==0&&n/i==i)
Sum+=1;
}
int f=1;
for (int i=1;i<=sum;i++)
{if (f==1)
F=f-1;
else if (f==0)
f=f+1;
}
System.out.println (f);
}
}
}
}

This topic is regular, write a few more you will find the law.

HDU2053. Java

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.