Nyist 77 light-on Problem

Source: Internet
Author: User

Turn on the light
Time Limit: 3000 MS | memory limit: 65535 KB
Difficulty: 1
Description
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 all the switches (the switched lights will be turned on, the lights will be turned off) numbered 3, and so forth. A total of K people asked which lights were on at last? Input: N and K, and output the number of lights on. K ≤ n ≤ 1000

Input

Enter a set of data: N and K

Output

Number of the lights on


Sample Input
7 3
Sample output
1 5 6 7

 

 

 

# Include <iostream>
Using namespace STD;
Int main ()
{
Int n, a [1000] = {0}, I, J, K;
Cin> N> K;
For (I = 1; I <= K; I ++)
For (j = 1; I * j <= N; j ++) // One Time ------ one time === exchange opposite
{If (a [I * j] = 1) A [I * j] = 0;
Else if (a [I * j] = 0) A [I * j] = 1 ;}

For (I = 1; I <= N; I ++) // turn on the light
{If (a [I] = 1)
Cout <I <"";}
Return 0;
}

 

# Include <stdio. h>
Int main ()
{
Int k, n, a [1002], I, J;
Scanf ("% d", & N );
Scanf ("% d", & K );
For (I = 1; I <= K; I ++)
{
For (j = 1; j * I <= N; j ++)
{
If (A [J * I]! = 1)
{
A [J * I] = 1;
}
Else
{
A [J * I] = 0;
}
}
}
For (j = 1; j <= N; j ++)
{
If (A [J] = 1)
{
Printf ("% d", J );
}
}
Printf ("\ n ");
}

 

 


# Include <iostream>
Using namespace STD;
Int main ()
{
Int N, K, a [1000], I;
Cin> N> K;
For (I = 0; I <n; I ++)
A [I] = 1;

For (I = 2; I <= K; I ++)
For (Int J = 0; j <n; j ++)
{
If (J + 1) % I = 0)
If (A [J] = 0) A [J] = 1;
Else a [J] = 0;
}

For (I = 0; I <n; I ++)
If (A [I] = 1) cout <I + 1 <"";
Cout <Endl;

Return 0;
}

 


# Include <stdio. h>
# Define n 1001
Int A [n] = {0 };
Int main ()
{
Int N, K, I, J;
Scanf ("% d", & N, & K );
For (I = 1; I <= K; I ++)
For (j = I; j <= N; j = J + I)
A [J] =! A [J];
For (I = 1; I <= N; I ++)
If (A [I]) printf ("% d", I );
Printf ("\ n ");

Return 0;
}

 


# Include <stdio. h>
# Include <string. h>
# Define maxn 1000 + 10
Int A [maxn];
Int main ()
{
Int I, j, N, K, first = 1;
// Freopen ("light. In", "r", stdin );
// Freopen ("light. Out", "W", stdout );
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 (first) First = 0;
Else printf ("");
Printf ("% d", I );
}
Printf ("\ n ");
Return 0;
}

 

 


# Include <iostream>
# Include <cstring>
Using namespace STD;
Const int M = 1000 + 10;
Int main (INT argc, char * argv [])
{
Int N, K, a [m], I, j, flag = 1;
Cin> N> K;
Memset (A,-1, sizeof ());
For (j = 1; j <= K; j ++)
{
For (I = 1; I <= N; I ++)
If (I % J = 0) A [I] =-A [I];
}
For (I = 1; I <= N; I ++)
{If (a [I] = 1)
If (flag = 1) {cout <I; flag = 0 ;}
Else cout <"" <I;
}
Cout <Endl;
Return 0;
}

 

 


# Include <malloc. h>
# Include <stdio. h>
# Include <string. h>

Int main ()
{
Int N, K, I, J;
Scanf ("% d", & N, & K );
Int * A = (int *) malloc (sizeof (INT) * n );
For (I = 0; I <n; I ++)
{A [I] = 0;} // The initialization array is 0. All lights are disabled.

For (I = 0; I <n; I ++)
For (j = 1; j <= K; j ++)
{
If (I + 1) % J = 0) {if (a [I] = 0) A [I] = 1; else a [I] = 0; // printf ("% d", a [I]);
} // If division is enabled, the status changes.
}
For (I = 0; I <n; I ++)
If (A [I] = 1) printf ("% d", I + 1 );
Putchar ('\ n ');

Return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.