Hide

Problem D
Range Sum

Write the function sum_of_range(start, end, step), which takes in three integers as parameters, start, end, and step. The function should return the sum of all numbers from start to end, both end points included, taking step size steps each increment.

Formally, you should compute the value of

\[ \sum _{i=0}^{\left\lfloor \frac{b-a}{k} \right\rfloor } a + i \cdot k \]

where $a$ is the value of start, $b$ is the value of end, and $k$ is the value of step.

Note that we are testing your code differently in this task, please only submit your function definitions, without any code outside the functions! The main python file, which handles input and output, is already provided. You can download and place the main file in the same directory as your python file. You can then run the main python file we provide to try out the samples.

Input

The input to the function will consist of three parameters.
The first parameter will be an integer $a$, the start of the sum, where $1 \leq a \leq 2000$.
The second parameter will be an integer $b$, the end of the sum, where $s \leq b \leq 2000$.
The third parameter will be an integer $k$, size of steps, where $1 \leq k \leq 100$. You need not verify this.

Output

The output of the function should be one integer, the sum over the given range.

Sample Input 1 Sample Output 1
1
10
2
25
Sample Input 2 Sample Output 2
1
10
1
55
Sample Input 3 Sample Output 3
5
10
7
5

Please log in to submit a solution to this problem

Log in