Rabbit Jumping Problem
Consider 'n' carrots numbered from 1 to 'n' and 'k' rabbits. Each rabbit jumps to carrots only at multiples of its respective jumping factor Aj (i.e., Aj, 2Aj, 3Aj, ...), for all rabbits from 1 to k.
When a rabbit reaches a carrot, it eats a little portion of it. All rabbits start from the same starting point. Your task is to determine and return the total count of carrots that remain uneaten after all rabbits have finished jumping.
Input:
The first line contains an integer 'T' indicating the number of test cases.
Each test case comprises two lines.
First line: two integers 'n' and 'k' indicating the number of carrots and rabbits.
Second line: 'k' space-separated integers representing the jumping factors of the rabbits.
Output:
A single integer for each test case indicating the number of carrots that were not eaten.
Example:
Input:
1
10 2
2 3
Output:
3
Explanation:
With 10 carrots and rabbits jumping on multiples of 2 and 3, carrots 2, 3, 4, 6, 8, 9, 10 will be eaten by the rabbits, leaving carrots 1, 5, and 7 uneaten.
Constraints:
- 1 <= 'T' <= 50
- 1 <= 'n', 'k' <= 3000
- 1 <= A[j] <= n, for all j from 1 to k
- Time Limit: 1 second
Be the first one to answer
Add answer anonymously...
Top DE Shaw Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in DE Shaw Software Developer
Stay ahead in your career. Get AmbitionBox app
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
Get AmbitionBox app