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
Chandan Mittal: 2013-06-25 05:57:16

@desire
no code posting here
Didn't read the footer notes??
3. For more discussion (hints, ideas, solutions) please visit our forum.

desire: 2013-06-26 00:10:36

Getting Wrong ANswer :( please suggest me ...

(abdelkarim)code has been removed by problem setter .

Last edit: 2013-06-26 00:10:32
BLANKRK: 2013-06-20 18:12:47

:D easy one . . .
jus read one line carefully...

Last edit: 2013-06-20 18:15:44
Yusro Tsaqova: 2013-06-11 02:17:11

@encrypted
1st testcase : 4
2nd testcase : 3

Chandan Mittal: 2013-05-25 22:40:10

AC :)

Last edit: 2013-06-25 05:55:42
!!.Nginx.!!: 2013-05-18 03:58:39

AC in 1st attempt.. :)
High School Problem.. :P

mbaros: 2013-01-19 18:08:24

Please anyone explain test #2

lovelotus: 2013-01-18 17:39:06

take care, the given list is the new list, not the original list... costed me worthless 8 WA's... :( :(

Nnavneetsinha: 2013-01-16 11:38:18

@utkarsh .I completely agree with u "Read each line carefully".
Finally AC.:)

Last edit: 2013-01-16 12:31:16

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