Thursday, January 15, 2015

ACM 2035. Another Dress Rehearsal / Очередной пробный тур

First of all, if X+Y is less than the sum than there is no answer, in all other cases we can find an answer pair for sure. Here is how we will find it. We will take the difference of the X+Y and the sum. Assuming that our answer pair is X and Y until the difference is 0. We take the difference of X+Y and sum and we subtract it from X, until either X becomes 0 or the difference. The rest difference, we will subtract from Y and the resulted X and Y will be out answer.