PCPC12J - Amr Samir

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

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

hide comments
2013-01-16 05:38:15 Utkarsh Shahdeo
Its easy..just read each line carefully!!
2013-01-15 13:30:01 ɥsǝןǝǝu
finally AC
Read descriptions carefully.....

Last edit: 2013-01-30 06:42:40
2013-01-10 13:38:33 bib
be careful: "The luckiest divisor is the divisor D that divides f where f is the maximum and D is the smallest one."

Last edit: 2013-01-10 14:22:49
2013-01-08 18:56:46 saket diwakar
finally got it...:)
2013-01-07 18:00:23 Atul Kashyap
piece of cake....!!
2013-01-02 17:48:57 Ankur Rastogi
Can we have a[i] as zero?
2013-01-01 15:18:55 Kevin Sebastian
soln id 8390559..repeatedly getting wa..any tricky test cases
2013-01-01 06:05:35 RAJDEEP GUPTA
@Seshadri R : The numbers can occur in any order. You cannot assume anything that is not written in the problem statement.
2013-01-01 03:33:11 Seshadri R
Can it be assumed that all the divisors be grouped together or they can occur anywhere (like in 3 3 5 3 5 4 7 4 3)?
2012-12-31 10:19:58 (Tjandra Satria Gunawan)(曾毅昆)
easy problem, no trouble at all...
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.