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