Euclid Guess Codeforces Solution | Codeforces Problem Solution 2022
Let's consider Euclid's algorithm for finding the greatest common divisor, where is a list:
function Euclid(a, b):
if a < b:
swap(a, b)
if b == 0:
return a
r = reminder from dividing a by b
if r > 0:
append r to the back of t
return Euclid(b, r)
There is an array of pairs of positive integers that are not greater than . Initially, the list is empty. Then
the function is run on each pair in . After that the list is shuffled and given to you.
You have to find an array of any size not greater than that produces the given list , or tell that no such array exists.
The first line contains two integers and (, ) — the length of the array and the constraint for integers in pairs.
The second line contains integers () — the elements of the array .
- If the answer does not exist, output .
- If the answer exists, in the first line output () — the size of your array , i. e. the number of pairs in the answer.
The -th of the next lines should contain two integers and () — the -th pair in .
If there are multiple valid answers you can output any of them.
No comments:
Post a Comment