Q10049: Selfdescribing Sequence

Solomon Golomb的自我描述序列(selfdescribing sequence)<f(1), f(2), f(3), ......>是一個唯一的不下降序列。在此序列的正整數的特質為k在序列中會出現連續f(k)次。這樣解釋你可能不太清楚,請看以下的表:

n 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
f(n) 1 2 2 3 3 4 4 4 5 5 5 6 6 6 6 7 7 7 7 8 8 8 8 9

你可以看到n=1, f(n)=1,代表1會在序列中出現1次。n=2, f(2)=2,代表2會在序列中出現2次。n=3, f(3)=2,代表3會在序列中出現2次。n=4, f(4)=3,代表4會在序列中出現3次。依此類推,若f(k)=x,則k會在序列中出現x次。

在本問題中,給你n,請你算出f(n)是多少。

Input

每組測試資料一列,含有1整數n(1 <= n <= 2000000000),n=0代表輸入結束。

Output

每組測試資料輸出一列,f(n)。

Sample Input

4
10
100
9999
123456
1000000000
0

Sample Output

3
5
21
356
1684
438744