Give Me an E

Time limit1sMemory limit128 MB

Summary
Find the n-th positive integer (n below 2^31) whose English spelling contains no letter E, and print it with thousands separators.
Level

Medium7 of 10

Topics
Math, Combinatorics, Implementation
Solved
No attempts yet

Problem

Everyone knows that “E” is the most common letter in English. When you spell integers out in words, it is interesting to see which ones do NOT use the letter “E”. For example, 6030 (six thousand thirty) uses no “E”, and neither does 4002064 (four million two thousand sixty-four).

It turns out that 6030 is the 64th positive integer whose spelling avoids “E”, and 4002064 is the 838th such number. Your job is to find the nn-th such number.

Note on spelling large numbers: 1,001,001,001,001,001,001,001,001,000 is spelled “one octillion, one septillion, one sextillion, one quintillion, one quadrillion, one trillion, one billion, one million, one thousand”.

Input

The input consists of several test cases. Each test case is a single positive integer nn (n<231n < 2^{31}) on its own line. A line containing 00 marks the end of the input. (The input contains no commas.)

Output

For each nn, print the nn-th positive integer whose spelling does not use the letter “E”, written with commas as thousands separators. You may assume every answer is less than 102810^{28}.

Examples1

  1. Example 1

    Input
    1
    10
    838
    0
    
    Expected output
    2
    44
    4,002,064