Statistics

Problem Statement for "WordNumber"

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

  1. 3

    5

    Returns: "ab"

    See the table above.

  2. 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.

  3. 26

    2000000000

    Returns: "flhomvx"

  4. 15

    1

    Returns: "a"

  5. 26

    456

    Returns: "qn"

  6. 2

    13

    Returns: "bba"

  7. 2

    14

    Returns: "bbb"

  8. 2

    15

    Returns: "aaaa"

  9. 2

    9

    Returns: "aba"

  10. 25

    15625

    Returns: "xxy"

  11. 25

    15626

    Returns: "xya"

  12. 17

    1999999999

    Returns: "dnnjadcm"

  13. 4

    13652

    Returns: "bdddddd"

  14. 4

    13651

    Returns: "bdddddc"

  15. 20

    20

    Returns: "t"

  16. 20

    21

    Returns: "aa"

  17. 20

    22

    Returns: "ab"

  18. 20

    40

    Returns: "at"

  19. 20

    41

    Returns: "ba"

  20. 26

    1987654321

    Returns: "fkgocac"

  21. 2

    7

    Returns: "aaa"

  22. 18

    1700430165

    Returns: "bmqpdqdi"

  23. 6

    1879066806

    Returns: "dffbdbecaaff"

  24. 19

    1833149783

    Returns: "asrfgrdj"

  25. 17

    1674669406

    Returns: "dafgnona"

  26. 17

    462567884

    Returns: "abbmemoi"

  27. 5

    816519128

    Returns: "cacbeaaeebdec"

  28. 24

    1660558457

    Returns: "hpmaiwq"

  29. 15

    14662179

    Returns: "addieci"

  30. 22

    40352794

    Returns: "greokt"

  31. 20

    1999886706

    Returns: "akdsepof"

  32. 7

    1681133903

    Returns: "efddbbedgaa"

  33. 2

    586596412

    Returns: "aaababbbbabbabbaaaaaaaabbbbab"

  34. 10

    1999927401

    Returns: "aiiiibgcja"

  35. 20

    1304372648

    Returns: "tglfklh"

  36. 14

    1558323530

    Returns: "njmffbch"

  37. 2

    2000000000

    Returns: "bbabbbaabbababbaababaaaaaaaaab"

  38. 25

    2000000000

    Returns: "hdsxxxy"

  39. 26

    1

    Returns: "a"

  40. 2

    1999999999

    Returns: "bbabbbaabbababbaababaaaaaaaaaa"

  41. 22

    1999999973

    Returns: "qnanogo"

  42. 26

    2000000000

    Returns: "flhomvx"

  43. 26

    1234000000

    Returns: "cyviitl"

  44. 3

    82

    Returns: "bbca"

  45. 2

    5

    Returns: "ba"

  46. 2

    25

    Returns: "baba"

  47. 3

    6

    Returns: "ac"

  48. 3

    3

    Returns: "c"

  49. 3

    565645454

    Returns: "ccbccacbcacbabcabb"

  50. 2

    26

    Returns: "babb"

  51. 26

    26

    Returns: "z"

  52. 2

    2000000000

    Returns: "bbabbbaabbababbaababaaaaaaaaab"

  53. 2

    20000000

    Returns: "aabbaaabaababbabaaaaaaab"

  54. 2

    8

    Returns: "aab"

  55. 2

    2000000

    Returns: "bbbabaaaabaabaaaaaab"

  56. 2

    1073741822

    Returns: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbb"

  57. 2

    16

    Returns: "aaab"

  58. 3

    9

    Returns: "bc"

  59. 25

    24

    Returns: "x"

  60. 22

    113379904

    Returns: "uuuuuv"

  61. 23

    2000000000

    Returns: "mkpuagq"

  62. 26

    700

    Returns: "zx"


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: