Topic Meaning:
http://acm.hdu.edu.cn/showproblem.php?pid=2053
give you n a lamp, just start all out, ask after an infinite number of operations, the status of the nth lamp.
Topic Analysis:
See code comments.
AC Code:
/** * @xiaoran * should be a problem of number theory, first simulation look (over), now look at this problem * Test instructions: give you n lights, just start all out, ask after an infinite number of operations, the nth lamp state * For the first operation, change the status of multiples of all I * found when operation to n+ After 1 times, it certainly doesn't affect N, the problem becomes the state of n after the operation N Times * analyzed below: The state of the first n is 0, if the nth lamp operates an even number of times, its state is still 0, * operation Odd number of times to 1, now to analyze for N: If I is an approximate of n, it will change the state of N, but *j=n/ I is also an approximate number of N, will also change the state of N back, to here can be found when the i=n/i, will be * on the state of N is affected, just start n state is 0, if n is a complete square number, it will become 1. */#include <iostream> #include <cstdio> #include <map> #include <cstring> #include <string > #include <algorithm> #include <queue> #include <vector> #include <stack> #include < cstdlib> #include <cctype> #include <cmath> #define LL long longusing namespace Std;int a[100005];int Main ( ) {int n; while (cin>>n) {int k= (int) (sqrt (n) +0.5); k*k==n?printf ("1\n"):p rintf ("0\n"); /** Analogue memset (A,1,sizeof (a)); for (int. i=2;i<=n;i++) {for (int j=i;j<=n;j+=i) {a[j]=!a[j]; }} if (n==1) printf ("1\n"); else printf ("%d\n", A[n]); **/}return 0;}
HDU 2051 Switch Game (analog/number theory)