Since most computers are binary machines, both powers of two and problems that involve only two values are important to computer scientists. The following problem has to do with powers of two and the digits 1 and 2.
Some powers of two as decimal values, such as 2
9 = 512 and 2
89 = 618,970,019,642,690,137,449,562,112 end in a string of digits consisting only of 1's and 2's (12 for 2
9 and 2112 for 2
89 ). In fact, it can be proved that:
For every integer R, there exists a power of 2 such that 2
K uses only the digits 1 and 2 in its last R digits.
This is shown a bit more clearly in the following table:
Your job is to write a program that will determine, for given R, the smallest K such that 2
K ends in a string of R digits containing only 1's and 2's.