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 R
_{1},R_{2},...,R_{n} combined in serial. The resistance is equal to R_{1}+R_{2}+...+R_{n}. Or
- several circuits R
_{1},R_{2},...,R_{n} combined in parallel. The resistance is equal to 1/((1/R_{1})+(1/R_{2})+...+(1/R_{n})).
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. |