The sum of all integers from 1 to 100 can be calculated by tricky expedient. We divide all the numbers in pairs 1 and 100, 2 and 99, 3 and 98, etc. The sum of each pair is 101. The number of all pairs is 100 / 2 = 50. Therefore, the sum equals to (1 + 100) * 100 / 2. For an odd number of terms works the same formula, for example: 1 + 2 + 3 = (1 + 3) * 3 / 2 = 6.
One integer n. Number n can be negative.
Print the sum of all integers from 1 to n. It is guaranteed that the sum is 64-bit signed integer type.
If n = -3, then the sum equals to 1 + 0 - 1 - 2 - 3 = -5.