Statistics

Problem Statement for "TriCount"

Problem Statement

We are interested in triangles that have integer length sides, all of which are between minLength and maxLength, inclusive. How many such triangles are there?

Two triangles differ if they have a different collection of side lengths, ignoring order. Triangles with side lengths {2,3,4} and {4,3,5} differ, but {2,3,4} and {4,2,3} do not. We are only interested in proper triangles; the sum of the two smallest sides of a proper triangle must be strictly greater than the length of the biggest side.

Create a class TriCount that contains a method count that is given ints minLength and maxLength and returns the number of different proper triangles whose sides all have lengths between minLength and maxLength, inclusive. If there are more than 1,000,000,000 return -1.

Definition

Class:
TriCount
Method:
count
Parameters:
int, int
Returns:
int
Method signature:
int count(int minLength, int maxLength)
(be sure your method is public)

Constraints

  • minLength is between 1 and 1,000,000, inclusive.
  • maxLength is between minLength and 1,000,000, inclusive.

Examples

  1. 1

    2

    Returns: 3

    The proper triangles with side lengths between 1 and 2 inclusive are {1,1,1} and {2,2,2} and {1,2,2}.

  2. 9

    10

    Returns: 4

    9,9,9 and 10,10,10 and 9,9,10 and 9,10,10

  3. 1

    1000000

    Returns: -1

    There are VERY many triangles with lengths in this range.

  4. 19

    1000

    Returns: 83540657

  5. 52

    2290

    Returns: 999746335

  6. 1000

    1000

    Returns: 1

  7. 1000

    1002

    Returns: 10

  8. 1398

    3217

    Returns: -1

  9. 1396

    3215

    Returns: 999998462

  10. 1000000

    1000000

    Returns: 1

  11. 999999

    1000000

    Returns: 4

  12. 2

    91

    Returns: 65850

  13. 100

    109

    Returns: 220

  14. 101

    1000

    Returns: 79158700

  15. 101

    2296

    Returns: 999518824

  16. 101

    2297

    Returns: -1

  17. 870300

    904813

    Returns: -1

  18. 749004

    884061

    Returns: -1

  19. 285716

    913050

    Returns: -1

  20. 574832

    662720

    Returns: -1

  21. 998652

    998753

    Returns: 182104

  22. 233086

    597151

    Returns: -1

  23. 426339

    808267

    Returns: -1

  24. 6981

    816216

    Returns: -1

  25. 358827

    982521

    Returns: -1

  26. 762782

    970746

    Returns: -1

  27. 663425

    753637

    Returns: -1

  28. 257407

    524141

    Returns: -1

  29. 910215

    910733

    Returns: 23434580

  30. 567533

    568212

    Returns: 52636760

  31. 243731

    905865

    Returns: -1

  32. 763534

    867041

    Returns: -1

  33. 906449

    920720

    Returns: -1

  34. 330460

    868616

    Returns: -1

  35. 844164

    947997

    Returns: -1

  36. 613430

    738821

    Returns: -1

  37. 303849

    395339

    Returns: -1

  38. 145552

    175569

    Returns: -1

  39. 881724

    959446

    Returns: -1

  40. 305995

    412459

    Returns: -1

  41. 701908

    878607

    Returns: -1

  42. 772512

    838755

    Returns: -1

  43. 963433

    969360

    Returns: -1

  44. 556661

    969565

    Returns: -1

  45. 966582

    976837

    Returns: -1

  46. 434066

    894713

    Returns: -1

  47. 776121

    912097

    Returns: -1

  48. 47469

    224039

    Returns: -1

  49. 892568

    974213

    Returns: -1

  50. 914529

    966829

    Returns: -1

  51. 79902

    850829

    Returns: -1

  52. 727421

    817195

    Returns: -1

  53. 438946

    689489

    Returns: -1

  54. 24569

    257839

    Returns: -1

  55. 470344

    802722

    Returns: -1

  56. 659716

    721500

    Returns: -1

  57. 1

    1000000

    Returns: -1

  58. 291688

    293504

    Returns: -1

  59. 3000

    4815

    Returns: 999800616

  60. 900000

    1000000

    Returns: -1

  61. 1

    2200

    Returns: 889149250

  62. 7500

    9998

    Returns: -1

  63. 4

    2200

    Returns: 889136062


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: