Let us play with even and odd numbers
All submissions for this problem are available.
You are given e even and o odd numbers. In a single operation, you change an even to odd number or vice versa. Find out min number of operations needed to
do such that ratio of even to odd numbers becomes 2 : 3. If it is impossible to do so, output -1.
- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
- For each test case, there will be a single line of input containing two space separated integers e and o.
- For each test case, output a single line containing a single integer corresponding to the answer of the problem.
- 1 ≤ T ≤ 10^5
- 1 ≤ e, o ≤ 10^9
Input: 3 2 3 3 2 3 3 Output: 0 1 -1
Example case 1. Ratio of even : odd numbers are already 2 : 3. So no need of any operation.
Example case 2. Change one even to odd, you will have 2 even and 3 odd satisfying the ratio. So only 1 operation is needed.
Example case 3. There is no way of doing operations which could make desired ratio.
|Time Limit:||3 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS|
Fetching successful submissions