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.

makeitdonesolo | 64 |

ShubhamJain18 | 64 |

Bishnu Dev Panda | 54 |

DanishBansal | 50 |

abhithakur588 | 50 |

Bishnu Dev Panda | 777 |

yk12 | 512 |

okayboss | 490 |

DevMittal | 472 |

VijethaShastri | 431 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4925 |

Quandray | 4547 |

Login to report an issue on this page.