Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5725 |

@blackshadows | 5685 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4908 |

@saiujwal13083 | 4156 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3511 |

@sushant_a | 3453 |

@KshamaGupta | 3318 |

@the_coder95 | 3302 |

Complete Leaderboard | |

Handle | Score |

@avaiesshaik782 | 786 |

@arpitsatnalika | 777 |

@tujhekya | 602 |

@prakharxyz | 601 |

@code_it_ | 591 |

@iamronak | 505 |

@imnm | 500 |

@pradeepkumarjad | 488 |

@satyam0460 | 481 |

@nitesha125 | 468 |

@Rahul Jadhav 1 | 466 |

Complete Leaderboard |

Given **N** leaves numbered from **1 to N** . A caterpillar at leaf **1**, jumps from leaf to leaf in multiples of A_{j} (A_{j}, 2A_{j}, 3A_{j}).

j is specific to the caterpillar. Whenever a caterpillar reaches a leaf, it eats it a little bit.. You have to find out how many leaves, from **1 to N**, are left uneaten after all** K** caterpillars have reached the end. Each caterpillar has its own jump factor denoted by **A _{j}**, and each caterpillar starts at leaf number 1.

**Input:**

The first line consists of a integer** T** denoting the number of testcases. **T** test cases follow. Each test case consists of two lines of input. The first line consists of two integers: **N,** which denotes the number of leaves; and **K, **which denotes the number of caterpillars. Second line of each test case consists of **K** space seperated integers denoting the jumping factor of caterpillars.

**Output:**

For each testcase, in a new line, print a single integer denoting the number of **uneaten leaves**.

**Constraints:**

1 <= T <= 100

1 <= N <= 10^{7}

1 <= K <= 10^{7}

1 <= A_{j} <= 100

**Example:**

**Input:**

1

10 3

2 3 5

**Output:**

2

**Explanation:**

**Testcase1: **The leaves eaten by the first caterpillar are (2, 4, 6, 8, 10).

The leaves eaten by the second caterpilllar are (3, 6, 9)

The leaves eaten by the third caterpilllar are (5, 10)

Ultimately, the uneaten leaves are 1, 7 and their number is 2

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Jumping Caterpillars

...

Please choose 'ReadOnlyMode' if you needn't to 'Edit' the problem e.g. viewing OJ's solution, TestCase Files (TCFs), TimeLimit etc.