fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int n, m;
  7. cin >> n;
  8. if (n < 0)
  9. {
  10. m = -n;
  11. }
  12. else
  13. {
  14. m = n;
  15. }
  16. unsigned long long int counter = ((1 + m) * m) / 2;
  17. if (n > 0)
  18. {
  19. cout << counter;
  20. }
  21. else if (n == 0)
  22. {
  23. cout << 1;
  24. }
  25. else
  26. {
  27. cout << counter * - 1 + 1;
  28. }
  29. return 0;
  30. }
Success #stdin #stdout 0s 15224KB
stdin
100
stdout
5050