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
krish_47: 2018-11-18 07:25:47

This problem can be solved in O(1) time .

mohameda7maa: 2018-10-04 08:33:49

a, b as input
iterate from a to b simple

Last edit: 2018-10-04 08:34:50
nadstratosfer: 2018-05-20 04:43:52

pintman: Not true, all input files contain exactly 2 space-separated numbers in a line. Got AC with a solution designed to crash if it was otherwise.

Last edit: 2018-05-20 04:44:43
pintman: 2018-05-19 08:49:30

It seems that input().split() (in python) results in three values for the first input but into two values for all others. Your input data may be not consistent. :(

freborn: 2018-03-23 16:56:13

AC in one go ! easy for a biginner ::

lohithsai: 2017-12-27 13:22:02

guys here it is very simple that given question is iterated sum just apply logic:
for(i=a;i<=b;i++){
sum=sum+i*i;
}

tranxuanbach: 2017-11-12 01:30:19

I hope this help !
http://mathforum.org/library/drmath/view/56920.html

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.


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