| ||NOTE: This problem statement contains superscripts that may not display properly if viewed outside of the applet.
Your friend's birthday is approaching, and he wants his age to be written in candles on his cake. In fact, he has already placed several candles on the cake. The candles are arranged in a single row, and there are two different colors of candles. One color represents the digit '0' and the other color represents the digit '1'. You don't want to relayout the candles from scratch, so you have to determine if there's a base for which the existing candles spell out your friend's age. To simplify the task, you can choose any strictly positive base, not necessarily an integer one.
For example, if the candles are "00010" and your friend's age is 10, then the candles spell out 10 in base 10 (decimal). If the candles are "10101" and your friend's age is 21, then you can say that "10101" is 21 in base 2 (binary). If the candles are "10100" and your friend's age is 6, then the candles spell out 6 in base sqrt(2)=1.41421356237.... Note that you are not allowed to rotate the cake, so "10" cannot be read as "01".
You are given a String candlesLine, where the i-th character is the digit ('0' or '1') represented by the i-th candle in the row of candles on the cake. You are also given an int age, which is your friend's age. Return the positive base for which the candles represent your friend's age. If there is no such base, return -1, and if there are multiple such bases, return -2.
|Method signature:||double getRadix(int age, String candlesLine)|
|(be sure your method is public)|
|-||The number anan-1...a1a0 in base B is equal to an*Bn + an-1*Bn-1 + ... + a1*B + a0.|
|-||The returned value must have an absolute or relative error less than 1e-9.|
|-||age will be between 1 and 100, inclusive.|
|-||candlesLine will contain between 1 and 50 characters, inclusive.|
|-||Each character in candlesLine will be '0' (zero) or '1' (one).|
|This is the first example from the statement: simply a decimal notation of the given age. Note that notation can have leading zeroes.|
|This is the second example from the statement: "10101" is a binary notation of the given age.|
|This is the third example from the statement.|
|In any base, "1" represents the age of 1, so it's impossible to get the age of 16.|
|In any base, "1" represents the age of 1.|