Skew Binary
#描述#
When a number is expressed in decimal, the k<sup>th</sup> digit represents a multiple of 10k. (Digits are<br>numbered from right to left, where the least significant digit is number 0.) For example,</p><p>81307<sub>10</sub> = 8×10<sup>4</sup> + 1×10<sup>3</sup> + 3×10<sup>2</sup> + 0×10<sup>1</sup> + 7×10<sup>0</sup><br>= 80000+ 1000+ 300 + 0 + 7<br>= 81307.</p>
<p>When a number is expressed in binary, the k<sup>th </sup>digit represents a
multiple of 2<sup>k</sup>. For example,</p>
<p>10011<sub>2</sub> = 1×2<sup>4</sup> + 0×2<sup>3</sup> + 0×2<sup>2</sup> + 1×2<sup>1</sup>
+ 1×2<sup>0</sup><br>
= 16 + 0 + 0 + 2 + 1<br>
= 19.</p>
<p>In skew binary, the k<sup>th</sup> digit represents a multiple of <sup>2k+1</sup> − 1.
The only possible digits are 0 and 1, except that the least-significant nonzero
digit can be a 2. For example,</p>
<p>10120<sub>skew</sub> = 1×(2<sup>5</sup>−1) + 0×(2<sup>4</sup>−1) + 1×(2<sup>3</sup>−1)
+ 2×(2<sup>2</sup>−1) + 0×(2<sup>1</sup>−1)<br>
= 31 + 0 + 7 + 6 + 0<br>
= 44.</p>
<p>The first 10 numbers in skew binary are 0, 1, 2, 10, 11, 12, 20, 100, 101,
and 102. (Skew binary is useful in some applications because it is possible to
add 1 with at most one carry. However, this has nothing to do with the current
problem.)</p>
<p>The input file contains one or more lines, each of which contains an integer
n. If n = 0 it signals the end of the input, and otherwise n is a nonnegative
integer in skew binary. For each number, output the decimal equivalent. The
decimal value of n will be at most 2<sup>31</sup> − 1 = 2147483647.</p>
#格式#
##输入格式##
##输出格式##
#样例1#
##样例输入1##
10120
200000000000000000000000000000
10
1000000000000000000000000000000
11
100
11111000001110000101101102000
0
##样例输出1##
44
2147483646
3
2147483647
4
7
1041110737
#限制#
1000ms
32768KB
#提示#
#来源#