Programming 2

Qn - 1

Hanabi

Its a festival whoohoo!!

We have two firework launchers a and b  launched by Taki and Mitsuha.


Mitsuha fires a firework every a minutes and Taki fires a firework every b minutes. 

They both start the fireworks simultaneously 


Each firework is visible in the sky for m+1 minutes after launch, i.e., if a firework was launched after x minutes after the installations were turned on, it will be visible every minute from x to x+m, inclusive.


What is the maximum number of fireworks that both Taki and Mitsuha will see in the night sky at the same time?


Input:


Each test consists of several test cases. The first line contains a single integer t(1≤t≤104) — the number of test cases. Then follow the descriptions of the test cases.


The first and only line of each test case contains integers a, b, m (1≤a,b,m≤1018) — the frequency of launching for the first installation, the second installation, and the time the firework is visible in the sky.


Output:

For each set of input data, output a single number — the maximum number of fireworks that can be seen simultaneously.


Sample Input:

6

6 7 4

3 4 10

7 8 56

5 6 78123459896

1 1 1

1 1 1000000000000000000


Output:

2

7

17

28645268630

4

2000000000000000002


Note: Solve this question using Python.

Qn - 2

When Mark wanted to created Facebook, He wanted to make sure that everyone in the website was connected to each other, as this would make spreading of information faster. If A is friend of B, B is friend of C, it means A is also friend of C. Help Mark identify if his given network is good or bad by checking if nobody is left out of the network.


Input:

- First line gives 2 inputs n m : (number of people in the network), (no of connections).

- Followed by m lines which has a b : (person 1), (person 2).


Ouput:

- good  : everyone is connected to each other.

- bad   : not everyone in the network is reachable.


Input 1:

4 3 

1 3

4 3

4 1


Output 1:

Bad


Input 2:

4 4

3 1

3 2

3 4

2 1


Output 2:

Good


Requirement: Use the concept of DFS in graphs.

Note: Solve this question using C/C++.

Qn - 3

Create a linkedlist data structure which has the following operations:

0       - Display the entire linkedlist

1 x     - Insert the value x as the new head value.

2 x y   - Insert the value x at the index y in the linkedlist. 


Input:

- First line will be T, the number of testcases/ operations.

- next T lines will be of the format given above, which can be 0, 1, 2.

Ouput:

- Mostly the entire linkedlist output when asked.


Input 1:

11

1 0

1 1

1 2 

1 3

1 4

1 5

0

2 6 1

0

2 6 0

0


Output 1

5 4 3 2 1 0 

5 6 4 3 2 1 0 

6 5 6 4 3 2 1 0 


Requirement: Use pointers in the linkedlist structure you create.

Note: Solve this question using C/C++.

Qn - 4

x - seed for srand()

y - number of arrays


Objective:

- Set the seed for the rand()

- Create y arrays such that the size of the arrays is the first y (random_values % 10000)

- Fill each of the arrays with random values array by array till each one of them is filled completely

- print out all the arrays after in the form `array[i][j] = value`


Sample input 1:

4 1


Sample Output 1:

array[0][0] = 83


Sample Input 2:

23 2


Sample Output 2:

array[0][0] = 34

array[0][1] = 74

array[1][0] = 84

array[1][1] = 2

array[1][2] = 84

array[1][3] = 19

array[1][4] = 55

array[1][5] = 39

array[1][6] = 66

array[1][7] = 17

array[1][8] = 44

array[1][9] = 83

array[1][10] = 19

array[1][11] = 11

array[1][12] = 7

array[1][13] = 1

array[1][14] = 36

array[1][15] = 83

array[1][16] = 73

array[1][17] = 1

array[1][18] = 74

array[1][19] = 58

array[1][20] = 42

array[1][21] = 2

array[1][22] = 33

array[1][23] = 33

array[1][24] = 94

array[1][25] = 19

array[1][26] = 15

array[1][27] = 96

array[1][28] = 5

array[1][29] = 1

array[1][30] = 23

array[1][31] = 89

array[1][32] = 56

array[1][33] = 7


Note: Solve this question using C.

Qn - 5

My friend Gian is very short and dumb, please help him find out how far he can go up :(


There is a stairway to heaven with n steps. The i'th step is aᵢ meters higher than its predecessor. The ground starts at 0 meters high, and the first step is a₁ meters higher than the ground. 

Gian is dumb, so he has q questions to ask, each denoted by integers q₁, q₂, q₃, etc. until qᵢ.


For each question qᵢ, you have to print the maximum possible height Gian can reach up to by climbing the stairway to heaven, if is legs are of length qᵢ. Gian can only climb the j-th step if his legs are of length at least aⱼ. In other words: kⱼ >= aⱼ for every step j climbed by Gian.


Input format:

t -> number of test cases 

n q => n -> number of steps, q -> number of questions 

n integers -> the height of the steps 

q integers -> the numbers for each question 


Output format:

The answer for each question qᵢ that Gian asks. 


Input:

3

4 5

1 2 1 5

1 2 4 9 10

2 2

1 1

0 1

3 1

1000000000 1000000000 1000000000

1000000000


Output:

1 4 4 9 9 

0 2 

3000000000