Skip to content

Commit becd8e1

Browse files
authored
Merge pull request #427 from sreelakshmig009/techgig
This will close issue #356(techgig problem)
2 parents 4a71ab7 + 4834f00 commit becd8e1

File tree

7 files changed

+317
-0
lines changed

7 files changed

+317
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Techgig Code Gladiators 2021 Solutions
2+
3+
### Language Used: Python3
4+
5+
* Content:
6+
7+
* Open Coding Round :
8+
9+
* <a href ="https://github.com/sreelakshmig009/CompetitiveProgrammingQuestionBank/blob/techgig/Techgig%20Code%20Gladiators%202021/open%20round/virus_outbreak.md">Virus Outbreak</a>
10+
11+
* <a href="https://github.com/sreelakshmig009/CompetitiveProgrammingQuestionBank/blob/techgig/Techgig%20Code%20Gladiators%202021/open%20round/prime_game.md">Prime Game</a>
12+
13+
* Semi Finals Round:
14+
15+
* <a href="https://github.com/sreelakshmig009/CompetitiveProgrammingQuestionBank/blob/techgig/Techgig%20Code%20Gladiators%202021/semifinals/jazzy%20and%20cricket%20balls.md">Jazzy And Cricket Balls</a>
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Prime Game
2+
3+
4+
5+
Rax, a school student, was bored at home in the pandemic. He wanted to play but there was no one to play with. He was doing some mathematics questions including prime numbers and thought of creating a game using the same. After a few days of work, he was ready with his game. He wants to play the game with you.
6+
7+
### GAME:
8+
9+
Rax will randomly provide you a range [ L , R ] (both inclusive) and you have to tell him the maximum difference between the prime numbers in the given range. There are three answers possible for the given range.
10+
<ol>
11+
<li>There are two distinct prime numbers in the given range so the maximum difference can be found.</li>
12+
<li>There is only one distinct prime number in the given range. The maximum difference in this case would be 0.</li>
13+
<li>There are no prime numbers in the given range. The output for this case would be -1.</li>
14+
</ol>
15+
16+
To win the game, the participant should answer the prime difference correctly for the given range.
17+
18+
#### Example:
19+
20+
##### Range: [ 1, 10 ]:
21+
22+
The maximum difference between the prime numbers in the given range is 5.
23+
Difference = 7 - 2 = 5
24+
25+
##### Range: [ 5, 5 ]:
26+
27+
There is only one distinct prime number so the maximum difference would be 0.
28+
29+
##### Range: [ 8 , 10 ]:
30+
31+
There is no prime number in the given range so the output for the given range would be -1.
32+
33+
Can you win the game?
34+
35+
<b>Input Format:</b>
36+
37+
The first line of input consists of the number of test cases, T
38+
Next T lines each consists of two space-separated integers, L and R
39+
40+
<b>Constraints:</b>
41+
42+
1<= T <=10
43+
2<= L<= R<=10^6
44+
45+
<b>Output Format</b>
46+
47+
For each test case, print the maximum difference in the given range in a separate line.
48+
49+
##### Sample Test Case:
50+
51+
Input:
52+
```
53+
5
54+
5 5
55+
2 7
56+
8 10
57+
10 20
58+
4 5
59+
```
60+
Output:
61+
```
62+
0
63+
5
64+
-1
65+
8
66+
0
67+
```
68+
Explanation:
69+
```
70+
Test Case 1: [ 5 - 2 ] = 3
71+
72+
Test Case 2: [ 7 - 2 ] = 5
73+
74+
Test Case 3: No prime number in the given range. Output = -1
75+
76+
Test Case 4: [ 19 - 11 ] = 8
77+
78+
Test Case 5: The difference would be 0 since there is only one prime number in the given range.
79+
```
80+
81+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
def main():
2+
3+
T = int(input())
4+
def isprime(n):
5+
if n<=1:
6+
return False
7+
for i in range(2,n):
8+
if n%i ==0:
9+
return False
10+
return True
11+
12+
# to run each testcase
13+
while testCase >0:
14+
LR = list(map(int,input().strip().split()))
15+
L = LR[0]
16+
R = LR[1]
17+
f = 0
18+
l = 0
19+
for i in range(L,R+1):
20+
if f ==0:
21+
if isprime(i):
22+
f=i
23+
else:
24+
i = i+1
25+
if l==0:
26+
if isprime(R):
27+
l=R
28+
else:
29+
R -=1
30+
if f!=0 and l!=0:
31+
break
32+
33+
if f!=0 and l!=0:
34+
print(l-f)
35+
else:
36+
print(-1)
37+
38+
T -=1
39+
40+
main()
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
## Virus Outbreak
2+
3+
In the Martian land faraway, a new virus has evolved and is attacking the individuals at a fast pace. The scientists have figured out the virus composition, V. The big task is to identify the people who are infected. The sample of N people is taken to check if they are POSITIVE or NEGATIVE. A report is generated which provides the current blood composition B of the person.
4+
5+
#### POSITIVE or NEGATIVE ?
6+
7+
If the blood composition of the person is a subsequence of the virus composition V, then the person is identified as POSITIVE otherwise NEGATIVE.
8+
9+
#### Example:
10+
11+
Virus Composition, V = coronavirus
12+
Blood Composition of the person , B = ravus
13+
14+
The person in question is POSITIVE as B is the subsequence of the V.
15+
16+
The scientists are busy with their research for medicine and request you to build a program which can quickly figure out if the person is POSITIVE or NEGATIVE. They will provide you with the virus composition V and all the people’s current blood composition. Can you help them?
17+
18+
<mark><b>Note</b>: The virus and blood compositions are lowercase alphabet strings.</mark>
19+
20+
#### Input Format:
21+
22+
The first line of the input consists of the virus composition, V
23+
24+
The second line of he input consists of the number of people, N
25+
26+
Next N lines each consist of the blood composition of the ith person, Bi
27+
28+
#### Constraints:
29+
30+
1<= N <=10
31+
32+
1<= |B|<= |V|<= 10^5
33+
34+
#### Output Format:
35+
36+
For each person, print POSITIVE or NEGATIVE in a separate line
37+
38+
Sample Test Case 1:
39+
40+
Input
41+
42+
```
43+
coronavirus
44+
3
45+
abcde
46+
crnas
47+
onarous
48+
```
49+
50+
Output
51+
52+
```
53+
NEGATIVE
54+
POSITIVE
55+
NEGATIVE
56+
```
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
def isSubsequence(V,B):
3+
list_v = []
4+
list_b = []
5+
for c in V:
6+
list_v.append(c)
7+
8+
for j in B:
9+
list_b.append(j)
10+
11+
vindex = 0
12+
bindex = 0
13+
while vindex < len(list_v) and bindex < len(list_b):
14+
if list_v[vindex] == list_b[bindex]:
15+
bindex += 1
16+
vindex += 1
17+
18+
if bindex == len(list_b):
19+
return True
20+
return False
21+
22+
V = str(input())
23+
N = int(input())
24+
for i in range(N):
25+
B = str(input())
26+
result = isSubsequence(V,B)
27+
if result == True:
28+
print("POSITIVE")
29+
else:
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Jazzy And Cricket Balls
2+
3+
Jazzy is good with bowling but is not good with studies. His mom wants him to focus on studies too and for this she has found an interesting way. She has brought N packets of balls which may or may not have the same number of balls in them. The balls in a packet are arranged in a linear manner and Jazzy wants to play with the balls.
4+
5+
She will give the balls to Jazzy only if he can tell the maximum number of moves required in which he can get to play with all the balls. There are few conditions though:
6+
7+
8+
* In one move, Jazzy can divide the number of balls in the packet into an equal number of groups only.
9+
10+
Example : Suppose there are 6 balls in the packet.
11+
12+
Jazzy can divide this packet in 3 ways.
13+
14+
1. Two groups of 3 balls each. (3, 3)
15+
2. Three groups of 2 balls each (2, 2, 2)
16+
3. Six groups of 1 ball each.
17+
18+
Note: Dividing a single group into multiple groups of equal number is considered one move only.
19+
20+
* Jazzy can get to play with the balls when they are present as a single unit only and not in any group of size greater than 1. Also, getting to play with a ball is considered a move.
21+
22+
Example: In a group there are 2 balls, then Jazzy cannot play with them until he further divides them into single-single units.
23+
24+
* The length of all the packets/groups should always be an integer.
25+
26+
Example: Number of Packets, N = 1
27+
Number of balls in packet = 6
28+
29+
Jazzy only cares about playing with the balls and needs your help in finding the maximum number of moves. Can you help him?
30+
31+
#### Input Format:
32+
33+
The first line of input consists of the number of packets, N.
34+
The second line of input consists of N space-separated integers representing the number of balls in the packet (length of the packet), Ni
35+
36+
#### Constraints:
37+
38+
1<= N <=100
39+
1<= Ni <=10^12 (1e12)
40+
41+
#### Output Format:
42+
43+
Print the required number of maximum moves to get to play with the balls.
44+
45+
##### Sample Test :
46+
47+
Input
48+
49+
```
50+
2
51+
6 1
52+
```
53+
54+
Output
55+
56+
```
57+
11
58+
```
59+
60+
Explanation
61+
62+
```
63+
For 6 numbers of balls in a packet, 10 moves are required as explained above.
64+
65+
For 1 ball, only 1 move is required.
66+
67+
Total number of moves = 10 + 1 = 11
68+
```
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# import the math module for mathematical functions
2+
import math
3+
# define the function moves
4+
def movess(v):
5+
# create a variable move to count the number of moves for balls in each packet
6+
move=v
7+
# initially seperate the balls into two groups
8+
while(v%2==0):
9+
v=v//2
10+
move+=v
11+
# keep increasing the counts while seperating the balls into groups
12+
for i in range(3,int(math.sqrt(v))+2,2):
13+
while(v%i==0):
14+
v=v//i
15+
move+=v
16+
if v>2:
17+
move+=1
18+
return move
19+
20+
# input the number of packets
21+
b=int(input())
22+
# input the number of balls in the packet
23+
j=list(map(int,input().strip().split(" ")))
24+
k=0
25+
# call the function moves for balls in every packet
26+
for w in j:
27+
k+=movess(w)
28+
print(k)

0 commit comments

Comments
 (0)