Statistics

Problem Statement for "AnEasyProblem"

Problem Statement

NOTE: This problem statement contains subscripts/superscripts that may not display properly if viewed outside of the applet.

For positive integers h and r (1 &lt= r &lt= h) we define sequence Fh,r as {1, 2, 3, ..., h-1, h, h-1, h-2, ..., r+1, r}. Let S(Fh,r) be the the sum of all numbers in Fh,r and N(Fh,r) - the length of Fh,r.

For example, F3,2 is {1, 2, 3, 2}, S(F3,2) = 1 + 2 + 3 + 2 = 8, and N(F3,2) = 4. F5,5 is {1, 2, 3, 4, 5}, S(F5,5) = 15, and N(F5,5) = 5.

You are given a long sum. Return minimal possible N(Fi,j) such that S(Fi,j) = sum. If there is no such sequence Fi,j, return -1 instead.

Definition

Class:
AnEasyProblem
Method:
solve
Parameters:
long
Returns:
int
Method signature:
int solve(long sum)
(be sure your method is public)

Constraints

  • sum will be between 1 and 1,000,000,000,000(10^12).

Examples

  1. 6

    Returns: 3

    When h = r = 3, S(Fh,r) = 6 and N(Fh,r) = 3. There is no other h,r satisfing S(Fh,r) = 6. So you should return 3.

  2. 7

    Returns: -1

  3. 100

    Returns: 15

  4. 1000000000000

    Returns: 1428571

  5. 999999911791

    Returns: 1414213

  6. 47124365373

    Returns: 308634

  7. 4736204061

    Returns: 97326

  8. 140103954579

    Returns: 529461

  9. 816163944355

    Returns: 1300945

  10. 23017224220

    Returns: 215155

  11. 161346308278

    Returns: 572647

  12. 435778978723

    Returns: 1195897

  13. 577650171865

    Returns: 1108929

  14. 873825006753

    Returns: 1360434

  15. 101591406

    Returns: 14507

  16. 35407220029

    Returns: 273778

  17. 623444060645

    Returns: 1141573

  18. 863856839528

    Returns: 1366675

  19. 20961597040

    Returns: 217215

  20. 44572429578

    Returns: 343004

  21. 173156982615

    Returns: 605250

  22. 461420359333

    Returns: 1295289

  23. 835409478789

    Returns: 1657701

  24. 36486315918

    Returns: 286059

  25. 146992497634

    Returns: 592755

  26. 372870554536

    Returns: 868983

  27. 401123360743

    Returns: 900665

  28. 7112113064

    Returns: 138040

  29. 292540696929

    Returns: 828029

  30. 660520945594

    Returns: 1240683

  31. 445815107724

    Returns: 1167708

  32. 25895913676

    Returns: 258507

  33. 83726282881

    Returns: 412746

  34. 721546056148

    Returns: 1254560

  35. 205166123940

    Returns: 643968

  36. 530601417714

    Returns: -1

  37. 361617111880

    Returns: -1

  38. 954650182726

    Returns: -1

  39. 133398683218

    Returns: 548367

  40. 322042233207

    Returns: -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: