Statistics

Problem Statement for "IntrospectiveNumbers"

Problem Statement

An introspective number is a positive integer such that each digit of the number tells you the number of occurrences of that digit in that number.

For example, the number 2144424 is introspective because it has one 1, two 2s, and four 4s.

Clearly there are only finitely many introspective numbers. Suppose we sorted all of them. Given the long index, find the introspective number with the given 0-based index in that sorted list, and return it as a String.

Definition

Class:
IntrospectiveNumbers
Method:
nth
Parameters:
long
Returns:
String
Method signature:
String nth(long index)
(be sure your method is public)

Notes

  • The total number of introspective numbers is greater than 10^18, so for any input that matches the constraints given below the return value is defined.

Constraints

  • index will be between 0 and 10^18, inclusive.

Examples

  1. 0

    Returns: "1"

    The smallest introspective number (i.e., the one at index 0) is clearly the number 1.

  2. 5

    Returns: "333"

    The only two-digit introspective number is 22. The three-digit ones are 122, 212, 221, and 333.

  3. 128

    Returns: "2144424"

    The correct answer for this index is the number mentioned in the statement.

  4. 266960

    Returns: "999299999912"

  5. 1

    Returns: "22"

  6. 2

    Returns: "122"

  7. 3

    Returns: "212"

  8. 4

    Returns: "221"

  9. 6

    Returns: "1333"

  10. 7

    Returns: "3133"

  11. 8

    Returns: "3313"

  12. 9

    Returns: "3331"

  13. 10

    Returns: "4444"

  14. 11

    Returns: "14444"

  15. 4718803

    Returns: "55777755772572"

  16. 255999072

    Returns: "17374427237774734"

  17. 104554406420

    Returns: "52656453643635626454"

  18. 5955217264

    Returns: "1577757766667655567"

  19. 550195858414

    Returns: "275253475457747743357"

  20. 128654

    Returns: "412555445452"

  21. 71655287405291

    Returns: "88835145483828525488354"

  22. 420843416012567979

    Returns: "2745241346576776356455376767"

  23. 56300

    Returns: "55335512523"

  24. 398384431

    Returns: "34743777737414227"

  25. 60055185958015

    Returns: "76747217676763243644673"

  26. 404568667768

    Returns: "245551364462653566436"

  27. 1408496021539386

    Returns: "6362638881858855288356656"

  28. 2507971

    Returns: "36663413646446"

  29. 14823990

    Returns: "266344263643664"

  30. 5380883297

    Returns: "1266767677733663772"

  31. 3158239170747

    Returns: "1577372445374557475732"

  32. 1310277910

    Returns: "238488888124438483"

  33. 885316765509372

    Returns: "4633657573577764675746546"

  34. 123498538724723365

    Returns: "746247547542356766566773573"

  35. 19608173632

    Returns: "6276736763662713777"

  36. 1744200488

    Returns: "344999999439294239"

  37. 123607717077

    Returns: "55646564436245625363"

  38. 94494

    Returns: "254544551452"

  39. 390160982005

    Returns: "243664552345546656361"

  40. 33064496

    Returns: "451543355234452"

  41. 85092

    Returns: "236666316362"

  42. 276590639

    Returns: "23437142374477777"

  43. 1193

    Returns: "244434323"

  44. 6643732625

    Returns: "2373777726737616666"

  45. 934493921437297340

    Returns: "4536776244635766176437552577"

  46. 431483439188104222

    Returns: "2756646735626737467557144357"

  47. 885273382061506565

    Returns: "4446725676555457763277363176"

  48. 710734785047140248

    Returns: "3745174342377766676525756546"

  49. 711707653598957062

    Returns: "3745576756752446172566737346"

  50. 745937495250479787

    Returns: "3767644643546527527167775536"

  51. 966382316436087433

    Returns: "4565747522167776666573434573"

  52. 675144401062860363

    Returns: "3671533675655427564764764772"

  53. 253686940656174981

    Returns: "1773675724476545567636462753"

  54. 507644075228405428

    Returns: "3355755544887318788788874477"

  55. 222156015705657670

    Returns: "1654377765577344657262436675"

  56. 551634392267340642

    Returns: "3466734177657447256557636527"

  57. 239058362267163199

    Returns: "1737746256665576756734452473"

  58. 123467908318593041

    Returns: "745884782855858778471747285"

  59. 852116347142611986

    Returns: "4364775323766442775665551677"

  60. 666728583426574532

    Returns: "3665267275576375776461435744"

  61. 618052119438884224

    Returns: "3576563472755445647361266777"

  62. 134613693185048385

    Returns: "766723188863868678787826773"

  63. 521805685870184105

    Returns: "3388865848626686564453824585"

  64. 762425824415489436

    Returns: "3777646747267542536634155657"


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: