Editorial for An Animal Contest 5 P2 - Permutations & Products
Submitting an official solution before solving the problem yourself is a bannable offence.
Since , there are only possible permutations. Casework can be done for each of them.
This editorial will highlight one of several solutions to this problem. If you have a different solution, feel free to share it in the comments!
We will query with , storing the result in an array (let's call it ). Let be the smallest element in and let be the largest element in . If , this means that . Otherwise, which implies that . Thus, we have found .
Now that we have found , we can divide every element in by it, and at this point, we have found every element in .