|
|
back to boardDiscussion of Problem 1068. SumC++ Solution with no loops Posted by Maksim 3 Jul 2024 16:30 Maybe someone will need it. You can read more about it here: https://en.wikipedia.org/wiki/Arithmetic_progression #include <iostream> using namespace std; int main() { int a; cin >> a; int result = a > 0 ? a * (a + 1) / 2 : - a * (a - 1) / 2 + 1; cout << result; } Edited by author 03.07.2024 16:31 Edited by author 03.07.2024 16:31 |
|
|