#K70762. Summing Integers in a Range
Summing Integers in a Range
Summing Integers in a Range
Given two integers \(a\) and \(b\), compute the sum of all integers between them (inclusive). If \(a \gt b\), swap them so that the sum is computed from the smaller number to the larger number.
You can use the formula for the sum of an arithmetic series:
\( S = n \times \frac{(first + last)}{2} \)
where \( n = (last - first + 1) \).
For example:
- If the input is
1 5
, the output should be15
. - If the input is
10 7
, the output should be34
(because the sum is computed from 7 to 10).
inputFormat
The input is read from standard input and consists of a single line containing two space-separated integers \(a\) and \(b\).
outputFormat
The output should be a single integer, representing the sum of all integers between \(a\) and \(b\) (inclusive), computed using the arithmetic series formula.
## sample1 5
15