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.
|
|
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 :
|
|
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?
|
Added by: | kuszi |
Date: | 2013-08-26 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |