Vassil from Lawnswood School, Leeds, Michael from Madras College St Andrews and Koopa Koo from Boston College all solved this problem, well done all of you.

Here is Vassil's solution:

Let f(n) denote the sum of the first n terms of the sequence
0, 1, 1, 2, 2, 3, 3,¼, p, p, p+1, p+1,¼.

First I tried with several numbers. Let n=15. Then f(15)=2*(1+2+3+4+5+6+7)=7*8 where the sequence is: 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7

Let n=14. Then f(14)=2*(1+2+3+4+5+6+7)-7=7*7 where the sequence is: 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7

Let n=17. Then f(17)=2*(1+2+3+4+5+6+7+8)=8*9 where the sequence is: 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8

Let n=16. Then f(16)=2*(1+2+3+4+5+6+7+8)-8=8*8 where the sequence is: 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8

I noticed that the formula for f(n) depends on whether n is odd or even.

Case I - n is odd, i.e. n=2k+1

Then
f(n)
= 2(1+2+...+k)
= 2k(k+1)/2
= æ
ç
è
n - 1
2
ö
÷
ø
æ
ç
è
n+1
2
ö
÷
ø
.

Case II - n is even, i.e. n=2k


f(n)
= 2(1+2+...+k) - k
= k2 + k - k
= k2
= æ
ç
è
n
2
ö
÷
ø
2

 
.

Now we have to calculate f(a+b)-f(a-b)

There are two cases. In the first case, when one of a and b is even and the other is odd, then (a+b) and (a-b) are both odd. Otherwise (a+b) and (a-b) are both even.

Case I (a+b) and (a-b) both odd.
f(a + b) - f(a - b)
= (a + b)2 - 1
4
- (a - b)2 - 1
4
= ab.
Case II (a+b) and (a-b) both even.
f(a + b) - f(a - b)
= (a + b)2
4
- (a - b)2
4
= ab.