Switch GameTime
limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 15008 Accepted Submission (s): 9158
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 is contains only a number n (0< n<= 10^5) in a line.
OutputOutput The condition of the n-th lamp after infinity operations (0-off, 1-on).
Sample Input
15
Sample Output
Ten Hint 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 the condition of the fifth lamp any more. So the answer is 0.
AuthorLL SourceCelebration Cup warm up Test Instructions:
First, put these beacons on the,12345678....... Infinity First All is off, that is all 0 first operation, marking is a multiple of 1, all become the opposite state, that is, all become 1. The second operation, marking is a multiple of 2, all become the opposite state, you can see, 2 4 6 ... Turned into a 0 ... The third operation, marking is a multiple of 3, all become the opposite state, you can see, 3 6 9 ... He asked you what the status of the N lamp finally became, such as the number 1th lamp, and finally became 1, no matter how many times the operation is 1. For example, the number 5th lamp finally becomes 0, no matter how many times the operation is 0. The state of n does not change when the number of operations is greater than N, because N is not a multiple of M (M>n).
Exercises
The idea is simply to ask N to have a few approximate (including 1 and itself) if there are odd number of approximate, it is the odd number of times, the result is 1; otherwise 0
AC Code:
#include <iostream> #include <cstdlib> #include <cstdio> #include <cmath> #include <cstring > #include <string> #include <cstdlib> #include <iomanip> #include <algorithm>typedef long Long ll;using namespace Std;int main () {int n,k,i;while (scanf ("%d", &n)!=eof) {k=0;for (i=1;i<=n;i++) {if (n%i==0) k++;} if (k%2==0) printf ("0\n"); elseprintf ("1\n");} return 0;}
HDU 2053 Switch Game (math problem)