← Back to topics
Topic

Task :: Instrukcije

D
Diabolic
Can somebody explain why in the example 1 3 , there is 1+2+2=5 ?
Thanks in advance.
A
Al3kSaNdaR
You should generate array to look like this 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6 6 6. N times number N, and you can see that sum of first, second and third element is 1 + 2 + 2 = 5.
D
Diabolic
Thanks for the reply. And what about
3 7
3+4+4+4, right?
As I can see 7-3=4 is telling as the number of integers to compute, right?
But what about 50 50?
50-50=0
A
Al3kSaNdaR
For input 3 7 output is
2 + 3 + 3 + 3 + 4 = 15

, and for input 50 50 answer is
10
.
You should include M - N + 1 numbers in the sum.
A
Al3kSaNdaR
I see that you are doing tasks in C / C++. You should generate array as I said, and then use this.


long Sum = 0;
for ( int i = A; i <= B; i++ )
{
Sum += x[i];
}
pritnf ( "%ld", Sum );
D
Diabolic
Thank you very much for the help. Now, I solved it.