Statistics

Problem Statement for "SumAndProductPuzzle"

Problem Statement

Consider the following story.

STORY STARTS HERE.

There were three mathematicians: Susan, Priscilla, and Bob. Bob picked two positive integers x and y such that x <= y. He then told their sum to Susan and their product to Priscilla. Susan and Priscilla both knew all the facts listed above. Then, Susan and Priscilla made the following statements:

  • Susan: "I am certain that you cannot determine my number."
  • Priscilla: "Thanks for telling me that. Now I'm sure that your number is S."

STORY ENDS HERE.

My friends Baska and Olivia are fond of puzzles. Recently, Baska told Olivia the above story. When telling the story, Baska used some specific positive integer (for example, 9) instead of S. Then, she asked Olivia to determine x and y. Olivia easily came up with the unique solution.

Of course, you don't know the integer Baska used instead of S. Instead, you are given two ints A and B. Find all S between A and B, inclusive, such that the above discussion between Baska and Olivia could have happened. Return the sum of all such S.

Definition

Class:
SumAndProductPuzzle
Method:
getSum
Parameters:
int, int
Returns:
long
Method signature:
long getSum(int A, int B)
(be sure your method is public)

Notes

  • Watch out for overflow. The return value may overflow a 32-bit integer variable.

Constraints

  • A will be between 1 and 5,000,000, inclusive.
  • B will be between A and 5,000,000, inclusive.

Examples

  1. 30

    33

    Returns: 33

    The only valid S in this range is 33. The unique pair (x,y) that corresponds to S=33 is (1,32).

  2. 8

    11

    Returns: 19

  3. 40

    43

    Returns: 0

    Sometimes the given range doesn't contain any valid S. In such case the correct return value is 0.

  4. 47

    74

    Returns: 168

  5. 4980000

    5000000

    Returns: 2874227618

  6. 1

    5000000

    Returns: 392026464258

  7. 15

    17

    Returns: 16

  8. 5

    13

    Returns: 24

  9. 5

    17

    Returns: 40

  10. 6

    10

    Returns: 19

  11. 11

    24

    Returns: 16

  12. 22

    23

    Returns: 0

  13. 13

    21

    Returns: 16

  14. 13

    21

    Returns: 16

  15. 3

    18

    Returns: 40

  16. 12

    15

    Returns: 0

  17. 22

    23

    Returns: 0

  18. 1

    20

    Returns: 40

  19. 25

    26

    Returns: 0

  20. 20

    28

    Returns: 28

  21. 4

    8

    Returns: 5

  22. 12

    29

    Returns: 44

  23. 12

    27

    Returns: 16

  24. 1

    18

    Returns: 40

  25. 2

    29

    Returns: 68

  26. 7

    18

    Returns: 35

  27. 1347866

    4245274

    Returns: 254951623100

  28. 78647

    3866303

    Returns: 240482270682

  29. 626694

    4200990

    Returns: 274286187172

  30. 501858

    4855606

    Returns: 366114754286

  31. 2558519

    2618585

    Returns: 4866755098

  32. 1041268

    4275773

    Returns: 271654676094

  33. 590189

    1663440

    Returns: 41894087002

  34. 128262

    4752069

    Returns: 355859819064

  35. 1213400

    4604548

    Returns: 308916063788

  36. 171253

    673440

    Returns: 8221024922

  37. 2180911

    2447952

    Returns: 19805432274

  38. 1747735

    4742564

    Returns: 301190276756

  39. 90090

    4939854

    Returns: 382998880466

  40. 308211

    4268526

    Returns: 288842106980

  41. 250598

    2171107

    Returns: 79502941394

  42. 259068

    1011368

    Returns: 17606373208

  43. 3332594

    3758415

    Returns: 46531557844

  44. 1569173

    4642734

    Returns: 297136496444

  45. 401656

    2547531

    Returns: 105892099896

  46. 151690

    4846636

    Returns: 369408454970

  47. 1325612

    3414096

    Returns: 158049133594

  48. 975190

    3676706

    Returns: 200908517284

  49. 425569

    3666311

    Returns: 213756358198

  50. 4753151

    4774294

    Returns: 3034569684

  51. 2406120

    4518476

    Returns: 225774917766

  52. 2105869

    4621606

    Returns: 261698106156

  53. 913974

    2468151

    Returns: 87205286804

  54. 264082

    4825867

    Returns: 365533145218

  55. 3701335

    4535374

    Returns: 105004456396

  56. 459629

    4788598

    Returns: 357314020636

  57. 2452205

    4418972

    Returns: 209096793338

  58. 3692128

    4599480

    Returns: 114801190330

  59. 81633

    1196094

    Returns: 25961040798

  60. 2500605

    2620114

    Returns: 9655063314

  61. 907944

    4950312

    Returns: 369202414974

  62. 791984

    4828506

    Returns: 355459409212

  63. 1964561

    3683117

    Returns: 152387901286

  64. 2115028

    3167912

    Returns: 88076238156

  65. 251170

    941934

    Returns: 15252708160

  66. 3359895

    4351447

    Returns: 117422622974

  67. 60909

    4938122

    Returns: 382895840476

  68. 494255

    4760556

    Returns: 352600447656

  69. 71002

    3687118

    Returns: 219700255080

  70. 1390829

    4628259

    Returns: 304127711348

  71. 790626

    2694221

    Returns: 109456726296

  72. 203626

    2146445

    Returns: 78237772558

  73. 576063

    4190821

    Returns: 273988126066

  74. 1830233

    4491013

    Returns: 261518848160

  75. 105621

    4294866

    Returns: 294159829916

  76. 3585153

    3697722

    Returns: 12173089064

  77. 12

    4999983

    Returns: 392026464234

  78. 10

    4999989

    Returns: 392026464244

  79. 7

    4999974

    Returns: 392021464273

  80. 18

    4999977

    Returns: 392021464238

  81. 3

    4999979

    Returns: 392021464278

  82. 6

    4999988

    Returns: 392026464253

  83. 12

    4999973

    Returns: 392021464254

  84. 2

    4999999

    Returns: 392026464258

  85. 14

    4999977

    Returns: 392021464254

  86. 15

    4999979

    Returns: 392021464254

  87. 5

    4999978

    Returns: 392021464278

  88. 13

    4999976

    Returns: 392021464254

  89. 22

    4999973

    Returns: 392021464238

  90. 23

    4999977

    Returns: 392021464238

  91. 3

    4999971

    Returns: 392021464278

  92. 3

    4999992

    Returns: 392026464258

  93. 15

    4999980

    Returns: 392026464234

  94. 27

    4999971

    Returns: 392021464238

  95. 9

    4999981

    Returns: 392026464253

  96. 2

    4999990

    Returns: 392026464258

  97. 1

    2

    Returns: 0

  98. 1

    4999900

    Returns: 391996464642

  99. 2

    5000000

    Returns: 392026464258

  100. 123

    5000000

    Returns: 392026463317

  101. 11

    4999987

    Returns: 392026464234

  102. 10000

    4990000

    Returns: 390524699790

  103. 3435

    5000000

    Returns: 392026002752

  104. 1

    4888888

    Returns: 375946584324

  105. 15

    5000000

    Returns: 392026464234

  106. 1

    4985799

    Returns: 390019194838


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: