Submit solution

Points: 7
Time limit: 2.0s
Memory limit: 256M

Author:
Problem types

Raymond is good at sequences. He has made a puzzle that no one in his class could solve. It involves taking a number, finding the number of letters it has, then making this number the new number, and doing this over and over again to form a sequence. Raymond found that he would always end up repeating forever at the number 4, because it has 4 letters, four. He showed some sample sequences to get 4, but none of his classmates could solve the puzzle. He is exhausted from having to count out new patterns, so he gives the task to you. You must write a program to display the sequence from an input to 4.

Numbers

You will use the following spellings:

1 = one     11 = eleven      30 = thirty           1000 = onethousand 
2 = two     12 = twelve      40 = forty            1090 = onethousandninety
3 = three   13 = thirteen    50 = fifty            2500 = twothousandfivehundred
4 = four    14 = fourteen    60 = sixty            5123 = fivethousandonehundredtwentythree
5 = five    15 = fifteen     70 = seventy          10 000 = tenthousand
6 = six     16 = sixteen     80 = eighty           100 000 = onehundredthousand
7 = seven   17 = seventeen   90 = ninety           1 000 000 = onemillion
8 = eight   18 = eighteen    100 = onehundred      10 000 000 = tenmillion
9 = nine    19 = nineteen    101 = onehundredone   100 000 000 = onehundredmillion
10 = ten    20 = twenty      200 = twohundred      1 000 000 000 = onebillion

Note: There are no spaces.

Input Specification

The input will consist of an integer N (1 \le N \le 2\times10^9), the number to start the sequence.

Output Specification

Output one integer on each line the sequence from N (exclusive) to 4 (inclusive).

Note: Do not prompt for input, as this will cause the judge to take the prompt as the solution.

Sample Input 1

6

Sample Output 1

3
5
4

Explanation for Sample Output 1

6 is spelled as six, which has 3 letters, so the next number will be 3. 3 is spelled as three, which has 5 letters, so the next number will be 5. 5 is spelled as five, which has 4 letters, so the next number will be 4. Once 4 is reached, the sequence is over.

Sample Input 2

101

Sample Output 2

13
8
5
4

Explanation for Sample Output 2

101 is spelled as onehundredone, which has 13 letters, so the next number will be 13. 13 is spelled as thirteen, which has 8 letters, so the next number will be 8. 8 is spelled as eight, which has 5 letters, so the next number will be 5. 5 is spelled as five, which has 4 letters, so the next number will be 4. Once 4 is reached, the sequence is over.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation.

Comments


  • 0
    Medi  commented on Nov. 15, 2018, 8:10 a.m.

    In the question, how would you name the number 1947471476?


    • 1
      Raymo111  commented on Nov. 30, 2018, 6:58 p.m. edited

      1,947,471,476

      onebillionninehundredfortysevenmillionfourhundredseventyonethousandfourhundredseventysix


    • 1
      geese  commented on Nov. 15, 2018, 12:33 p.m. edit 2

      Probably just put in each unit like the others, separating by million/thousand (word form)


  • 0
    BULLET999  commented on Oct. 4, 2018, 7:15 p.m.

    ok, so how do you make 7 into seven?


    • 1
      ss__jonathan  commented on Oct. 4, 2018, 8:18 p.m.

      Hint: Think about storing the words into an array (or vector or Arraylist)


  • 1
    Green  commented on Oct. 3, 2018, 5:48 p.m.

    Hey, I just spent a lot of time on my Python code (that I hope works properly). However, when I went to submit it, I found out that the library that I used can't be imported. I was wondering if there is a way to fix that (or at least if there is a way to know what libraries can't be used for the future). Thanks!


    • 1
      Xyene  commented on Oct. 4, 2018, 12:52 a.m. edited

      Only packages included in a standard CPython installation are available. That excludes pretty much everything on PyPI.


      • 1
        Green  commented on Oct. 9, 2018, 9:23 p.m.

        Okay, thanks a lot!


  • 4
    ScriptKitty  commented on Oct. 1, 2018, 5:50 p.m. edited

    Explanation for Sample Output 2

    onehundredone = 13 letters, thirteen = 8 letters


    • 1
      Raymo111  commented on Oct. 1, 2018, 6:17 p.m.

      Fixed it.