|A serial-parallel resistor circuit is either
- a single resistor. The resistance of such circuit is equal to the resistance of the resistor. Or
- several circuits R1,R2,...,Rn combined in serial. The resistance is equal to R1+R2+...+Rn. Or
- several circuits R1,R2,...,Rn combined in parallel. The resistance is equal to 1/((1/R1)+(1/R2)+...+(1/Rn)).
Given two positive integers a and b, your task is to build a serial-parallel resistor circuit that has resistance equal to a/b. You are only allowed to use two kinds of resistors: R=1 and R=2. Return the minimal number of resistors needed. If the circuit cannot be built with 16 or less resistors, return -1.