Statistics

Problem Statement for "NthFraction"

Problem Statement

Given an int, bound, consider the infinite set of all reduced fractions whose numerator is a positive integer and whose denominator is a positive integer less than or equal to bound. Now, find the Nth smallest (indexed from 1) fraction and return it as a String in the form "a/b", with no leading zeros in either integer. See example 0 for further clarifications.

Definition

Class:
NthFraction
Method:
getFraction
Parameters:
int, int
Returns:
String
Method signature:
String getFraction(int N, int bound)
(be sure your method is public)

Notes

  • A reduced fraction is one of the form a/b for which there is no integer g > 1 such that both a and b are divisible by g.

Constraints

  • N will be between 1 and 2,000,000,000, inclusive.
  • bound will be between 1 and 1000, inclusive.

Examples

  1. 5

    3

    Returns: "4/3"

    The ordered set of fractions is {1/3, 1/2, 2/3, 1/1, 4/3, 3/2, 5/3, ...}

  2. 1000

    100

    Returns: "18/55"

  3. 1

    1000

    Returns: "1/1000"

  4. 502

    1000

    Returns: "2/999"

  5. 2000000000

    1000

    Returns: "6377551/970"

  6. 1000000

    1

    Returns: "1000000/1"

  7. 978871174

    791

    Returns: "2101464/409"

  8. 211033151

    530

    Returns: "836278/339"

  9. 1897558520

    223

    Returns: "26569811/213"

  10. 1818573594

    421

    Returns: "3968335/118"

  11. 1786769080

    84

    Returns: "29696993/36"

  12. 1122702492

    83

    Returns: "31448249/60"

  13. 947659870

    180

    Returns: "8728446/91"

  14. 1328721448

    902

    Returns: "3644406/679"

  15. 1931065210

    842

    Returns: "4840637/541"

  16. 978162986

    910

    Returns: "1849285/476"

  17. 913373255

    51

    Returns: "18131479/16"

  18. 57253700

    845

    Returns: "177746/675"

  19. 939807242

    723

    Returns: "1718641/291"

  20. 333327222

    301

    Returns: "3037919/252"

  21. 863014414

    177

    Returns: "11637974/129"

  22. 305498078

    962

    Returns: "643412/593"

  23. 64588953

    916

    Returns: "93649/370"

  24. 963908914

    905

    Returns: "1094516/283"

  25. 1882908983

    924

    Returns: "3299202/455"

  26. 324460650

    482

    Returns: "1892901/413"

  27. 97866287

    224

    Returns: "1003724/157"

  28. 1196881018

    60

    Returns: "29324671/27"

  29. 847029527

    93

    Returns: "7972793/25"

  30. 1351665213

    876

    Returns: "1396504/241"

  31. 1199178371

    943

    Returns: "3467651/783"

  32. 201538669

    881

    Returns: "648887/761"

  33. 813050585

    231

    Returns: "7893695/158"

  34. 1561327055

    207

    Returns: "17414343/146"

  35. 596874816

    306

    Returns: "2975991/142"

  36. 266243948

    575

    Returns: "1176503/445"

  37. 497342903

    457

    Returns: "3241571/415"

  38. 1568024423

    970

    Returns: "4905626/895"

  39. 1650509770

    304

    Returns: "13840261/236"

  40. 311364467

    326

    Returns: "2587170/269"

  41. 720482147

    847

    Returns: "973357/295"

  42. 458055071

    126

    Returns: "8057674/85"

  43. 1368843542

    271

    Returns: "12486114/205"

  44. 458319758

    853

    Returns: "1696071/820"

  45. 417617383

    622

    Returns: "1893683/534"

  46. 1857498109

    475

    Returns: "8345939/309"

  47. 1471906446

    424

    Returns: "10534733/392"

  48. 645279128

    669

    Returns: "1330697/281"

  49. 1780641416

    300

    Returns: "10983590/169"

  50. 246786984

    883

    Returns: "208865/201"

  51. 878554472

    393

    Returns: "4385308/235"

  52. 1898623837

    727

    Returns: "8526436/723"

  53. 1951545595

    467

    Returns: "11726629/400"

  54. 1386120445

    977

    Returns: "4645521/974"

  55. 1482221261

    90

    Returns: "30481163/51"

  56. 184605237

    940

    Returns: "528437/769"

  57. 2000000000

    1000

    Returns: "6377551/970"

  58. 999999999

    755

    Returns: "3036204/527"

  59. 1000000000

    1000

    Returns: "1522065/463"

  60. 1999999999

    999

    Returns: "4647917/706"

  61. 999999999

    999

    Returns: "1537236/467"

  62. 2000000000

    2

    Returns: "1000000000/1"

  63. 12

    5

    Returns: "5/4"

  64. 6

    3

    Returns: "3/2"

  65. 2000000000

    1

    Returns: "2000000000/1"


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: