UVa 10014 - Simple calculations

UVa 10014 - Simple Calculations

 * http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=955

Explanation
This problem can be solved by repeated substitution.

We are given:

An = (An-1 + An+1) / 2 - Cn

Or rearranging:

2An = An-1 + An+1 - 2Cn

We can use this to solve for An-1:

3An-1 = 2An-2 + An+1 - 2Cn - 4Cn-1

And so on:

4An-2 = 3An-3 + An+1 - 2Cn - 4Cn-1 - 6Cn-2

So at the end we get:

(n+1)A1 = nA0 + An+1 - 2Cn - 4Cn-1 - 6Cn-2 - ... - (2n)C1