Jumping Game Problem Statement

In this problem, you have ‘n’ carrots lined up and denoted by numbers 1 through ‘n’. There are ‘k’ rabbits, and each rabbit can jump to carrots that are multiples of its unique jumping factor.

Rabbits start from the same point, and each time a rabbit lands on a carrot, it eats some of it. Your task is to calculate how many carrots remain uneaten after all rabbits have finished jumping.

Input:

The first line contains an integer ‘T’, representing the number of test cases.
For each test case:
The first line contains two integers, ‘n’ and ‘k’, denoting the number of carrots and rabbits, respectively.
The second line contains ‘k’ space-separated integers; each integer is a rabbit's jumping factor.

Output:

Output a single integer for each test case, representing the number of carrots that remain uneaten.

Example:

Input:
1
10 2
2 3
Output:
3

Constraints:

  • 1 ≤ ‘T’ ≤ 50
  • 1 ≤ ‘n’, ‘k’ ≤ 3000
  • 1 ≤ A[j] ≤ n, for all j from 1 to k

Note: You are not required to handle any input/output operations. Implement the given function to solve the problem.

AnswerBot
10d

Calculate uneaten carrots after rabbits jump based on their unique factors.

  • Iterate through each rabbit's jumping factor and mark the carrots they land on as eaten

  • Calculate the remaining uneaten carrot...read more

Help your peers!
Add answer anonymously...
Nagarro Technical Trainee 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