Media.net OA || aug 2023 || on Campus
Anonymous User
412

Q1)Omega Primes
Carl is bored of playing with ordinary prime numbers. Thus, he comes up with some special numbers called Omega Primes.

A number X
is called Omega Prime, if there exists no perfect square Y(Y>1)
such that Y
divides X
.

For example, 6 is an Omega Prime because there is no perfect square except 1 that divides 6.

On the other hand, 12 is not an Omega Prime as 4 (which is a perfect square) is a divisor of 12.

Carl decides to play a bit more with Omega Primes. He has an array A
of integers. Carl wants to find the number of different subsets such that the product of elements for each subset, results in an Omega Prime. Help Carl find this number.

Since this number can be large, output the answer modulo 109+7
.

Input
The first line contains an integer 1≤n≤20000
denoting size of array A
The second line contains n
space separated integers, where 1≤ith≤n
integer denotes 1≤A[i]≤30
Output
Output the answer as described in statement.

Examples
input
3
2 4 3
output
3
input
3
2 2 2
output
3
input
6
2 30 15 18 24 22
output
6

Q2)Hungry Policemen
You are given a graph G of N nodes and M edges and each edge has some time associated with it.
There is a policeman standing on each node except Node N.
All of them get a report that there is thief on Node N and the policemen start moving towards it, but all of them have been hungry for days, so they are looking to visit a few restaurants as well, before reaching the node N.
There are K restaurants present on some nodes, and each restaurant has some satisfaction. Now, a policeman will only go to a restaurant if and only if the satisfaction he receives by reaching the restaurant is greater than the time he has invested in reaching there and then going to the Node N.
Find and return the number of policemen who will have a meal at a restaurant.
Input Format:
The first argument contains an integer A, representing the number of nodes.
The second argument of input contains a 2 d matrix of size M x 3, B, where Node B[i][0] and Node B[i][1] are bidirectionally connected with an edge that takes B[1][2] time to go through it.
The third argument of input contains a 2-d matrix of size K x 2, C, where Node C[i][0] has a restaurant that has C[i][1] satisfaction.
Output Format: Return an integer representing the number of people who will have a dinner at the restaurant.
Constraints:
2 <- N <- 50000
1 <= M <= 100000

Output Format:
Return an integer representing the number of people who will have a dinner at the restaurant.
Constraints:
2 < N <- 50000
1 <= M <= 100000
1 <= K, B[i][e], 8[i][1] <= N
1 <= B[i][2] <= 1e4
1 <= C[i][1] <= 1e9
Example:
Input 1: A=4 B = [ [1, 2, 2], [2, 4, 1], [4, 3, 10], [3, 1, 1] ] C = [ [1, 1] ]
Output 1: 2
Explanation 1: Policemen at Node 1 and Node 3 will have a meal at node 1 without wasting any time.

Q3) Orange Tax

You live in orange town. There are a lot of markets around that are connected with roads. These markats sell oranges at some prices. The town is not very well developed and they still use carts to transport goods from one place to the other. The roads connect two markets together and have two attributes associated with them. One is the price to go from one market to the other in an empty cart and the other is the tax factor. The tax factor is the number by which the price associated with a road needs to be multiplied, so it can go from one market to the other if you are carrying oranges in your cart. So if a road's original price was 5 coins and tax factor was 6, then in an empty cart it would take 5 coins to travel the road, but if the cart contained oranges, it would cost 5*6=30 coins.

You wonder what would be the cheapest way to buy oranges if you were initially at each market. You can either buy at the market you are at or travel to some other market, buy oranges there, and travel back to the original market

You are given an integer A denoting the number of total markets in orange town, an integer array B denoting the price of purchasing oranges at each market and a 2-D array C containing the information about the roads. First two values denote the market numbers that are bi-directionally connected via a road, 3rd value is the price, while the 4th one is the tax factor.

Find and return the required array. The minimum cost to buy oranges at each market such that the starting and ending point is that market.

Problem Constraints

2 <= A <= 1e5
B.size() == A
1 <= B[i] <= 1e7
1 <= C.size() <= 2e5
1 <= C[0] <= A
1 <= C[1] <= A
1 <= C[2] <= 1e3
1 <= C[3] <= 5

Input Format

The first argument is the integer A. The second argument is the integer array B, and the third argument is the 2-D integer array C.

Output Format

Return an integer array as per the given problem.

Example Input

Input 1:

A = 2
B = [11 1]
C = [ [2 1 1 2] ]

Input 2:

A = 2
B = [1 1]
C = [ [2 1 2 4] ]

Example Output

Output 1:
[4 1]
Output 2:
[1 1]

Explanation

Explanation 1:

For the first market, you can travel to the second market (1 cost), buy oranges there (1 cost) and return back to the first market (1*2 cost) for a total of 4 cost.
For the second market, 1 is already the lowest you can get.

Explanation 2:

For both markets, 1 is the lowest so it is the best answer.

Comments (2)