Loading Now

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 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 by 20: 1,2,4,5,10,20.
    Numbers that are divisible by 8: 1,2,4,8.
    When we shuffle these numbers into a list. We has a list contains all divisors of these 2 numbers.
    Note that the given listOfDivisors 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 of x and y.
    2 ≤ n ≤ 128
  • [Input] array.interger listOfDivisors
    The list contains all divisors of either x and y. If there is a number z such that z is divisible by both x and y, z will appear 2 times in this list.
    1 ≤ listOfDivisors[i] ≤ 104
  • [Output] array.interger
    The initial numbers x and y
    Note that x >= y

Post Comment

Contact