From 280922cc0b67fa8a7f930b9a1130522a04c733f4 Mon Sep 17 00:00:00 2001 From: TurinTech Bot Date: Fri, 19 Jul 2024 09:03:28 +0000 Subject: [PATCH] Artemis Changes --- src/control/double.cc | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/control/double.cc b/src/control/double.cc index bb9dba1..9cf94db 100644 --- a/src/control/double.cc +++ b/src/control/double.cc @@ -24,15 +24,11 @@ DoubleForLoop::SumSquare(int n) { * * @param n * @return the sum of all triangle numbers from T(1) to T(n) - */ + */ long DoubleForLoop::SumTriangle(int n) { - long sum = 0; - for (int i = 0; i < n + 1; i += 1) { - for (int j = 0; j < i; j += 1) { - sum = sum + (long) j; - } - } + if (n <= 0) return 0; + long sum = (long)n * (n - 1) * (n + 1) / 6; return sum; } @@ -98,4 +94,4 @@ DoubleForLoop::SumMatrix(std::vector> matrix) { } } return sum; -} +} \ No newline at end of file