For example, if the light is turned on
There are n lamps numbered 1 ~ N. 1st people turn on all the lights, 2nd people press the switch in multiples of 2 (these lights will be turned off ), 3rd people press the switch in multiples of 3 (the switched light will be turned on, the switched light will be turned off), and so on. A total of k people asked which lights were on at last? Input: n and k, and output the numbers of open and so on. K <= n <= 1000.
Example input: 7 3
Sample output: 1 5 6 7
Solution: open an array that is large enough to simulate the entire process ~
Code:
# Include
# Include
# Define MAX 1000 + 10int a [MAX]; int main () {int I, j, n, k; memset (a, 0, sizeof ()); scanf ("% d", & n, & k); for (I = 1; I <= k; I ++) for (j = 1; j <= n; j ++) if (j % I = 0) a [j] =! A [j]; for (I = 1; I <= n; I ++) if (a [I]) {if (I = n) printf ("% d \ n", I); else printf ("% d", I);} return 0 ;}