Description
There are m lights, numbered for 1~m, respectively controlled by the corresponding m-switch. Start with all the switches facing up (up for, light on), and then do the following: numbers usually 1 times the lamp in the opposite direction dial a switch; is a multiple of 2 of the lamp again in the opposite direction dial a switch, is 3 times the lamp and the opposite direction to dial a switch, ..., until the multiple of M is the lamp again direction dial a switch. Please input an integer m from the keyboard to represent the number of lights, find out the number of lights (not lit) that are extinguished and the number and output.
Input
Enter an integer m (1<=n<=100).
Output
The output is two lines, the first line is the number of lights that are out of state, and the second line is the number of the last light that was extinguished (each data is displayed as a field width of 4 columns).
Sample Input
100
Sample Output
1 4 9 81 100
HINT
Output control is%4d
Train of thought: we can let the light be 1, turn off the light for-1. The C language code is as follows #include <stdio.h>
int main ()
{
int M;
int i,j,light[128],number=0;
scanf ("%d", &m);
for (i=1;i<=m;i++)///array light to be assigned a value of 1
Light[i]=1;
for (i=1;i<=m;i++)
{
for (j=1;j<=m;j++)
{
if (j%i==0)//Every time the first light starts to try, if it can be divisible by I, close (turn on) the light
{
LIGHT[J]=-1*LIGHT[J];
}
}
}
for (i=1;i<=m;i++)
{
if (light[i]<0)//If the lamp is off, count it once
Number+=1;
}
printf ("%d\n", number);
for (i=1;i<=m;i++)
{
if (light[i]<0)
{
printf ("%4d", I);
}
}
printf ("\ n");
return 0;
}