ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1068. Sum

C++ 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