Prince Roy, the undisputed ruler of the world
You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.
Time Limit: 4.0 s
Memory Limit: 256.0 MB
Description
Prince Roy is ready to conqure the world with his unlimited number of army and his great magical power. But there still has \(N\) more kingdom to be owned. As he wants to be the undisputed ruler of the world he is now preparing his army to conqure those \(N\) kingdoms.
In a battle with the \(i\)-th kingdom Prince Roy has to lose \(Ai\) amount of his army. But some of the kingdoms are very afraid of Prince Roy-s magical power \(K\) that they surrender infront of him without any battle.
The \(i\)-th kingdom will chose a battle with Prince if \(Ai\) is divisible by the magicical power \(K\), otherwise they will surrender without any battle.
Prince Roy can pick only one value of \(K\) in range from 1 to \(X\) (inclusive). Help him to chose the value of \(K\) so that he can win all \(N\) kingdom by loosing the minimum number of army.
If there has many \(K\) that helps Roy to lose minimum number of army, print the smallest \(K\) among all.
Input
first line of input takes an integer \(T\) : number of testcase
first line of each testcase takes two integer \(N , X\) : number of kingdoms and upper limit of \(K\)
second line of each tasecase takes input of \(N\) numbers
1 <= \(T\) <= 1000
1 <= \(N\) <= \(10^5\)
1 <= \(X\) <= \(10^6\)
1 <= \(Ai\) <= \(10^6\)
sum of N over all testcase will not exceed \(10^5\)
Output
One integer, in each of the \(T\) line : the optimal value of \(K\)
Sample
Input | Output |
---|---|
|
|
In first testcase, no battle will happen if Prince Roy chose K = 6,7,8,9,10. so the smallest k is 6.
In the second testcase, Prince Roy has to battle only with the 5-th kingdom and lose 4 army. it can be shown that he can not chose any other value of \(K\) that will cost him less than 4 army.
Brain Booster #3
- Status
- Done
- Rule
- ACM/ICPC
- Problem
- 9
- Start at
- 2024-05-06 15:00
- End at
- 2024-05-06 18:00
- Duration
- 3.0 hour(s)
- Host
- Partic.
- 91