TopCoder problem "WordNumber" used in SRM 267 (Division II Level Three)



Problem Statement

    It is possible to number all the words that could be formed from a specified alphabet. One way to do it is to put the words in order based on length, with words of common length ordered alphabetically. Using this scheme, if we use the alphabet consisting of just the 3 letters 'a', 'b', and 'c' then the words are numbered:
   1:a 2:b 3:c 4:aa 5:ab 6:ac 7:ba 8:bb   etc.
There are an infinite number of possible words, but each has its own positive number.

We want to be able to find the word that corresponds to any given number. Create a class WordNumber that contains a method theWord that is given alpha, the number of letters in the alphabet, and n, the number of a word. It returns the String that is the word corresponding to n.

The alphabet to be used is the first alpha letters of the normal lowercase alphabet, with their usual alphabetical ordering.

 

Definition

    
Class:WordNumber
Method:theWord
Parameters:int, int
Returns:String
Method signature:String theWord(int alpha, int n)
(be sure your method is public)
    
 

Constraints

-alpha will be between 2 and 26, inclusive.
-n will be between 1 and 2,000,000,000, inclusive.
 

Examples

0)
    
3
5
Returns: "ab"
See the table above.
1)
    
3
13
Returns: "aaa"
Extending the table above, we find that word 12 is "cc" so the next word, word 13, must be the first 3 letter word.
2)
    
26
2000000000
Returns: "flhomvx"
3)
    
26
456
Returns: "qn"

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=3488

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=8000&pm=3488

Writer:

dgoodman

Testers:

PabloGilberto , brett1479 , Olexiy

Problem categories:

Math