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.
AnswerBot
4mo

Given an array of prime numbers representing switches and an integer K, find the Kth glowing bulb when all switches are turned on.

  • Iterate through each prime number in the array and calculate the numbe...read more

Help your peers!
Select
Add answer anonymously...

Infosys System Engineer Specialist interview questions & answers

A System Engineer Specialist was asked Q. What is thrashing in an Operating System?
A System Engineer Specialist was asked Q. What are ACID properties?
A System Engineer Specialist was asked Q. What are NoSQL databases?

Popular interview questions of System Engineer Specialist

A System Engineer Specialist was asked Q1. What is thrashing in an Operating System?
A System Engineer Specialist was asked Q2. What are ACID properties?
A System Engineer Specialist was asked Q3. What are NoSQL databases?
Infosys System Engineer Specialist Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits