#K93042. Sequence Sum
Sequence Sum
Sequence Sum
You are given two integers, start and end. Your task is to compute the sum of the sequence of numbers from start to end (inclusive). If start is greater than end, the answer is 0.
For an arithmetic sequence, the sum can be computed using the formula [ S = \frac{n(a_1+a_n)}{2} ] where (n) is the number of terms, (a_1) is the first term, and (a_n) is the last term. However, a simple loop or built-in summing functionality can be used given that the range is small.
Example:
If the input is 1 5
, then the sequence is 1, 2, 3, 4, 5 and the output should be 15
.
inputFormat
The input consists of a single line containing two space-separated integers representing start and end respectively.
outputFormat
Output a single integer which is the sum of all the numbers from start to end inclusive. If start > end, output 0.## sample
1 5
15