Skip to content

sumkindofproblem

bradendubois edited this page Nov 24, 2021 · 9 revisions

Sum Kind of Problem

ID: sumkindofproblem

Difficulty: 1.5

CPU Time: 1 second

Memory: 1024 MB

Solution

Three formulas can be used for the sum of the first N, positive, odd, and even integers.

  • Positive = (N * (N + 1)) / 2
  • Odd = N * N
  • Even = N * (N + 1)
  • Can even just do odd first and add N to it to get even.
Clone this wiki locally