F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Aronson

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 125    Accepted Submission(s): 79


Problem Description
Aronson's sequence ak is a sequence of integers defined by the sentence "t is the first, fourth, eleventh, ... letter of this sentence.", where the ... are filled in appropriately so that the sentence makes sense. The first few values are 1, 4, 11, 16, 24, 29, 33, 35, 39, .... Note the non-letter characters and spaces are not considered in the formulation of the sequence. When k <= 100000, it turns out that ak <= 1000000.

To formulate the sequence, you must be able to write the ordinal numbers in English. The ordinal numbers are first, second, third, ..., while the cardinal numbers are one, two, three, .... It is easiest to define the ordinals in terms of the cardinals, so we describe these first.

A cardinal number less than twenty is written directly from the first two columns of table 1 (3->three, 17->seventeen, etc.). A cardinal number greater than or equal to twenty, but less than one hundred is written as the tens part, along with a nonzero ones part (40-> forty, 56->fifty six, etc). A cardinal number greater than or equal to one hundred, but less than one thousand, is written as the hundreds part, along with a nonzero remainder (100->one hundred, 117->one hundred seventeen, 640->six hundred forty, 999->nine hundred ninety nine). A cardinal number greater than or equal to one thousand, but less than one million, is written as the thousands part, along with a nonzero remainder (12345->twelve thousand three hundred forty five). An ordinal number is written as a cardinal number, but with the last word ordinalized using the columns three and four of table 1.

Some example ordinal numbers are 3rd->third, 56th->fifty sixth, 100th->one hundredth, and 12345th->twelve thousand three hundred forty fifth.
 

Input
The input consists of a number of cases. Each case is specified by a positive integer k on one line (1 <= k <= 100000). The sequence of k values will be non-decreasing. The input is terminated by a line containing a single 0.
 

Output
For each k, print the value of ak on one line. The values of ak will be at most 1000000.
 

Sample Input
1 3 9 0
 

Sample Output
1 11 39 Table 1 n cardinal nth ordinal 1 one 1st first 2 two 2nd second 3 three 3rd third 4 four 4th fourth 5 five 5th fifth 6 six 6th sixth 7 seven 7th seventh 8 eight 8th eighth 9 nine 9th ninth 10 ten 10th tenth 11 eleven 11th eleventh 12 twelve 12th twelfth 13 thirteen 13th thirteenth 14 fourteen 14th fourteenth 15 fifteen 15th fifteenth 16 sixteen 16th sixteenth 17 seventeen 17th seventeenth 18 eighteen 18th eighteenth 19 nineteen 19th nineteenth 20 twenty 20th twentieth 30 thirty 30th thirtieth 40 forty 40th fortieth 50 fifty 50th fiftieth 60 sixty 60th sixtieth 70 seventy 70th seventieth 80 eighty 80th eightieth 90 ninety 90th ninetieth 100 hundred 100th hundredth 1000 thousand 1000th thousandth
 

Hint

 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 21:46:27, Gzip enabled