PCPC12J - Amr Samir

no tags 

Amr started to learn division. So he gave a list of numbers to his friend and asked him to find all the divisors of each number in the given list. Now Amr has a new list of numbers containing all divisors of his original list.

As Amr loves playing with numbers, he now thinks about the repeated numbers in the new list of divisors. However this time Amr is interested in the luckiest divisor!

Lucky divisor is defined by Amr as follows: a divisor D is lucky if D divides f, where f is the frequency of this number D in the new list. Obviously f must be greater than zero.

The luckiest divisor is the divisor D that divides f where f is the maximum and D is the smallest one.

Since Amr is too lazy to write a program that solves this problem, he decided to submit it to the PCPC chief judge to put it as a problem for the teams to write a solution to it. Can you write this program for Amr?

Input

The first line contains a positive integer t <= 100, then follow t test cases. Each test case start with a line containing a single positive integer n <= 10000 number of divisors in Amr’s new list, then follows n positive integers a1, ai, ... an (ai <= 100).

Output

Your code should print an integer for each test case representing the luckiest divisor or -1 if there is no lucky divisor.

Sample

Input
2
5
2 2 3 3 3
7
2 2 2 2 3 3 3

Output
3
2

hide comments
Pranshul Agarwal: 2012-12-31 05:15:25

@ Ankit ans to your first case is -1 and second case is invalid...

Last edit: 2012-12-31 11:23:24
Aditya Pande: 2012-12-31 04:42:39

unexpected input cost me one WA

Last edit: 2012-12-31 09:01:44
Ankit Paharia: 2012-12-29 20:51:50

_Static_assert: according to the statement, The frequency of 3 is 3 and 2 is 2. So, the smallest number which belongs to the maximum frequency i.e. 3 is 3. 3 divides 3 so the answer is 3.

Ankit Paharia: 2012-12-29 20:48:30

getting WA...
plzz give the correct output for the following testcases..
7
7 7 7 7 2 2 2
5
0 0 0 1 2
my answers are -1 and 0..

Parit Agarwal: 2012-12-29 09:15:05

How is the answer for Case#1 is 3 ?
Should it not be -1 ?


Added by:abdelkarim
Date:2012-12-28
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:The First Palestinian Collegiate Programming Contest