Numbers with prime frequencies greater than or equal to k
Submissions: 974   Accuracy:

26.93%

  Difficulty: Easy   Marks: 2

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.

 

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

Contributor: Ankit Sharma
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.



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

to report an issue on this page.