Timer is Running

Winter is Coming
Submissions: 936   Accuracy:


  Difficulty: Easy   Marks: 2

Winter is coming, along with winter comes the white walkers who may destroy every human life on the planet. Only Brandon can stop it from happening but he is kidnapped by the White Walkers. His brother Jon wishes to set him free so that they can stop the destruction.
To set his brother free Jon has to kill the White Walkers who stand against the cave where his brother is kept as slave. Jon has somehow managed to place few of his men among the White Walkers who may help him in rescuing Brandon. Jon has the power to kill at most K White Walkers at a time, after which he would need one of his friends to help him gain back his power.

The N White Walkers (all assumed to be White Walkers apparently) stand in the given order denoted by some numbers. The ith person will have the number a[i] associated with them. Jon can identify his friend with the help of the numbers. If the number is prime, it is Jon’s friend who stands there else it’s the White Walkers.

Given the order, comment whether Jon will be able to rescue his brother or not.

The first line contains T denoting number of test cases.
For each of the test case the first line contains two Integers N and K, the second line contains N space separated integers.

Print 1 if Jon is able to rescue his brother, 0 if he cannot.

1 <= T <= 10
1 <= K <= N <=10^5
1 <= A[i] <= 10 ^5

5 2
6 3 4 5 6
6 3
1 2 10 4 6 8

First case: Jon can kill at most 2 White Walkers before reaching his friend. He kills the first (6) and he finds his friend (3) then again he kills one (4) and finds his friend (5). He now only has to kill one White Walker (6) to reach his brother.

** For More Input/Output Examples Use 'Expected Output' option **

Author: ShivamKD

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.