values of n positive integers. Take every pair of indices i < j and compute the greatest common divisor of values[i] and values[j]. That gives n · (n - 1) / 2 numbers; sort them in non-decreasing order.
You are also given an array positions. For each positions[k], find the number at that position (0-based) in the sorted list of gcds, and return the answers in the same order.values=[6, 9, 4], positions=[0, 1, 2] → [1, 2, 3]
The pair gcds are (6, 9) → 3, (6, 4) → 2, (9, 4) → 1. Sorted, that is [1, 2, 3].
values=[8, 12, 8, 5], positions=[5, 0, 4, 4] → [8, 1, 4, 4]
The six pairs give gcds 1, 1, 1, 4, 4, 8 in sorted order. Position 5 holds 8, position 0 holds 1 and position 4 holds 4. Positions may repeat.
values=[7, 7], positions=[0] → [7]
values=[6, 9, 4], positions=[0, 1, 2]
[1, 2, 3]
Run checks the first 3 tests in your browser. Submit checks all 45 tests on the server, hidden ones included.