You are given an array of size N. You need to find elements which appear prime number of times in the array with minimum K frequency (frequency >= K).

**Input:**

The first line of the input contains a single integer T, denoting the number of test cases. Then T test case follows. Each testcase contains two lines of input:-

The size of the array N and minimum frequency K separated by a space.

The elements of the array separated by spaces.

**Output:**

For each testcase, print the elements that have prime frequency with their frequency >=K. Print the output in sorted order. If there are no such elements then print -1.

**Constraints:**

1<=T<=105

1<=N<=1000

1<=K<=10

1<=A[i]<=10000

**Example:**

**Input:**

2

13 2

11 11 11 23 11 37 51 37 37 51 51 51 51

3 1

11 22 33

**Output:**

37 51

-1

**Explanation:**

For testcase 1: 11's count is 4, 23 count 1, 37 count 3, 51 count 5. 37 and 51 are two number that appear prime number of time and frequencies greater than or equal to K=2.

For testcase 2: K=1, and all three elements occur extactly 1 times. Unfortunately, 1 is not prime, so we don't print any element. We, instead, print a -1.

Author: Soul_xhacker

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.

tushki | 198 |

namansharmacse17 | 110 |

TusharMittal3 | 70 |

adkeaesph | 57 |

deepakchoudhary11 | 48 |

ARUN_PUNDIR | 720 |

manishgupta8497 | 623 |

AMAN__JAIN | 596 |

Abhimanyu_kumar | 562 |

Bicky_Shokeen | 532 |

blackshadows | 5335 |

Ibrahim Nash | 5223 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4584 |

Login to report an issue on this page.