Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
C++ code to kid chair association
Suppose we have a number n. We have to find an array A of size n. There are n tables and each table has 4 chairs. Chairs are numbered from 1 to 4n. It is known that two kids who sit on chairs with numbers a and b (a != b) will indulge if −
gcd(a,b) = 1 or,
a divides b or b divides a.
We want to seat the kids so there are no 2 of the kid that can indulge. More formally. We have to find the chair association.
So, if the input is like n = 4, then the output will be [14, 10, 12, 8], (other answers are also possible).
Steps
To solve this, we will follow these steps −
for initialize i := (2 * n), when iExample
Let us see the following implementation to get better understanding −
#includeusing namespace std; void solve(int n){ for (int i = (2 * n); i Input
4Output
8, 10, 12, 14,
Advertisements
