Sum of Consecutive Integers
InterviewTime limit0.25sMemory limit128 MB
Given two integers, print the sum of all integers in the closed range between them, handling either order.
- Level
Easy2 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
Given two integers A and B, compute the sum of every integer between them, including both endpoints. A may be greater than B; in that case, still sum every integer in the closed interval between the two values.
Input
The first line contains two integers A and B separated by a space.
- -2,147,483,648 ≤ A, B ≤ 2,147,483,647
Output
Print the sum of every integer between A and B on the first line. The output value is guaranteed to be between -2,147,483,648 and 2,147,483,647, inclusive.