Statistics

Problem Statement for "TriangleCount"

Problem Statement

Given an equilateral triangle with side length N divided into a triangular grid of triangles with side length 1, count the total number of triangles present in the grid. For example, if N is 4:


         /\
        /__\
       /\  /\
      /__\/__\
     /\  /\  /\
    /__\/__\/__\
   /\  /\  /\  /\
  /__\/__\/__\/__\

Here there are ten right-side-up and six up-side-down triangles with a side length of 1, six right-side-up and one up-side-down triangles with a side length of 2, three right-side-up triangles with a side length of 3, and one right-side-up triangle with a side length of 4. The total number of triangles is 27.

Definition

Class:
TriangleCount
Method:
count
Parameters:
int
Returns:
int
Method signature:
int count(int N)
(be sure your method is public)

Constraints

  • N will be between 1 and 500, inclusive.

Examples

  1. 2

    Returns: 5

    There are four small triangles and one big triangle.

  2. 3

    Returns: 13

  3. 4

    Returns: 27

    This is the example from the problem statement.

  4. 5

    Returns: 48

  5. 100

    Returns: 256275

  6. 1

    Returns: 1

  7. 500

    Returns: 31406375

  8. 6

    Returns: 78

  9. 7

    Returns: 118

  10. 8

    Returns: 170

  11. 9

    Returns: 235

  12. 10

    Returns: 315

  13. 15

    Returns: 988

  14. 20

    Returns: 2255

  15. 25

    Returns: 4303

  16. 50

    Returns: 32825

  17. 200

    Returns: 2025050

  18. 300

    Returns: 6806325

  19. 400

    Returns: 16100100

  20. 450

    Returns: 22907925

  21. 499

    Returns: 31218625

  22. 500

    Returns: 31406375

  23. 100

    Returns: 256275

  24. 1

    Returns: 1

  25. 97

    Returns: 234073

  26. 499

    Returns: 31218625

  27. 3

    Returns: 13


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: