A corridor contains N (1 ≤ n ≤ 65535) lamps, numbers 1, 2, 3 ,... N-1 and N. Each lamp is controlled by a wire pulling switch. Start, all the lights are turned off.
N students passed through the corridor. The first student pulls the switch of the electric lamp whose number is a multiple of 1, and the second student pulls the switch of the electric lamp whose number is a multiple of 2; then the third student pulls the switch of the electric lamp whose number is a multiple of 3. Then, the nth student pulls the switch of the electric lamp whose number is a multiple of N. After N students finished according to this rule, there were several lights in the corridor. Note: The number of electric lights is the same as that of students.
Input: number of electric lights
Output: Number of lights on
# Include <iostream> # include <string. h> using namespace STD; int main () {int I, j, N, Count = 0; int light [1, 100]; memset (light, 0, sizeof (light )); cin> N; for (I = 1; I <= N; I ++) // μúi § éú{ for (j = 1; j <N; j ++) // à-μ {If (J % I = 0) light [J] ++ ;}} for (I = 1; I <= N; I ++) {If (light [I] % 2 = 1) Count ++;} cout <count <Endl ;}
Number of lights on