SMPSUM - Iterated sums


Please compute the sum of squares for the given numbers: a, a+1, ..., b-1, b.

Input

Two numbers: a and b separated by space, where 1 <= a <= b <=100.

Output

Computed sum: a*a + (a+1)*(a+1) + ... + (b-1)*(b-1) + b*b

Example

Input:
1 4

Output:
30

Example 2

Input:
5 6

Output:
61

hide comments
rushikeshkoli: 2017-09-02 15:41:25

when a==b, it will simply output the square of either a or b.

Last edit: 2017-09-02 16:04:53
sekhar21: 2017-06-20 22:36:14

what will happen if a == b?

udayraj_123: 2016-06-13 21:37:09

@ryukerg You are right, deriving a formula is a way.

steamycoffee: 2016-05-12 23:02:18

"Two numbers: a and b separated by SPACE" this is wrong. The two numbers are separated by "Enter". If you try to solve it when they are separated by space you will get a wrong answer as result.
Edit: this comment is just valid if you use c++ and typeconversion from string to int!

Last edit: 2016-05-12 23:44:19
ryukerg: 2016-04-13 21:39:38

This is possible to solve in O(1) time. Not just solvable in O(b-a+1) time;

anonimowy: 2016-02-19 14:23:43

Simple

sakkket: 2016-01-06 15:32:33

its simple :
since a<b
for examble a=1 & b =4
it goes as (start with a) 1*1 + 2*2 + 3*3 + 4*4 (upto b)

ani_coder1995: 2015-12-13 10:23:15

it says to compute the squares of all integers between a and b including both

Mohit: 2015-11-21 15:58:45

Can someone please explain the question more clearly?
What does a*a + (a+1)*(a+1) + ... + (b-1)*(b-1) + b*b mean? the ... part i.e upto what length this multiplication should go a*a + (a+1)*(a+1) only or upto a*a + (a+1)*(a+1)+ (a+2)*(a+2) or even more?


Added by:kuszi
Date:2013-08-26
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64