
findTwoInitialNumbers
Recently you have received two positive integer numbers x and y. You forgot them, but you remembered a shuffled list containing all divisors of x
(including 1
and x
) and all divisors of y
(including 1
and y
). If z
is a divisor of both numbers x
and y
at the same time, there are two occurrences of z
in the list.
For example, if x=4
and y=6
then the given list can be any permutation of the list [1,2,4,1,2,3,6]
. Some of the possible lists are: [1,1,2,4,6,3,2]
, [4,6,1,1,2,3,2]
or [1,6,3,2,4,1,2]
.
Your problem is to restore suitable positive integer numbers x
and y
that would yield the same list of divisors (possibly in different order).
It is guaranteed that the answer exists, i.e. the given list of divisors corresponds to some positive integers x
and y
.
Example:
- For
n = 10
,listOfDivisors = [10, 2, 8, 1, 2, 4, 1, 20, 4, 5]
.
The output should be:findTwoInitialNumbers=[20,8].
Because:
Numbers that are divisible by20
:1,2,4,5,10,20.
Numbers that are divisible by8
:1,2,4,8.
When we shuffle these numbers into a list. We has a list contains all divisors of these2
numbers.
Note that the givenlistOfDivisors
is one of permutations of the above list.
Input/Output
- [Execution time limit] 0.5s in C++, 3s in Java and C#, 4s in Python, Go and JS
- [Input] interger n
the number of divisors ofx
andy
.2 ≤ n ≤ 128
- [Input] array.interger listOfDivisors
The list contains all divisors of eitherx
andy
. If there is a numberz
such thatz
is divisible by bothx
andy
,z
will appear2
times in this list.1 ≤ listOfDivisors[i] ≤ 104
- [Output] array.interger
The initial numbersx
andy
Note thatx >= y
Post Comment