Glowing Bulbs Problem Statement

You have an infinite number of electric bulbs, each assigned a unique integer starting from 1. There are 'N' switches, each labeled with a unique prime number. When a switch labeled with a prime number 'p' is turned ON, all bulbs numbered as multiples of 'p' start glowing. For example, turning ON a switch labeled 2 will result in bulbs numbered 2, 4, 6, 8, 10, etc., glowing.

You are given an array/list 'LABELS' consisting of 'N' unique prime integers representing the labels of the switches, and an integer 'K'. Your task is to find the integer assigned to the Kth glowing bulb when all these switches are turned ON.

Input:

The first line of input contains an integer ‘T’ denoting the number of test cases. Then ‘T’ test cases follow.

The first line of each test case consists of two space-separated integers ‘N’ and ‘K’ respectively.

The second line of each test case consists of ‘N’ space-separated prime integers representing the array/list ‘LABELS’.

Output:

For each test case, print the integer assigned to the Kth glowing bulb when all the given switches in ‘LABELS’ are turned ON.

Print the output of each test case on a separate line.

Example:

Consider 3 switches with labels [3, 5,  7] and we need to find the 5th glowing bulb from the start after turning these 3 switches ON.
We can see that bulbs numbered  3, 6, 9, 15, 18 … will glow if the switch having label 3 is turned ON.
The bulbs numbered 5, 10, 15, 20 … will glow if the switch having label 5 is turned ON.
The bulbs numbered 7, 14, 21, 28 … will glow if the switch having label 7 is turned ON.
It implies that bulbs numbered 3, 5, 6, 7, 9, 10, 14, 15, 18, 20, 21… will glow when these three switches are turned ON.
The 5th glowing bulb from start is assigned integer 9. Thus, we should return 9.

Constraints:

  • 1 ≤ T ≤ 50
  • 1 ≤ N ≤ 10
  • 1 ≤ K ≤ 1012
  • 1 < LABELS[i] < 30 where LABELS[i] is a prime integer and all integers in array/list ‘LABELS’ are distinct.
  • Time limit: 1 sec

Note:

You do not need to print anything; it has already been taken care of. Just implement the given function.
Be the first one to answer
Add answer anonymously...
Infosys System Engineer Specialist Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter