UVa 10014 - Simple calculations

10014 - Simple Calculations

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

Summary
This problem can be solved by repeated substitution.

Explanation
We are given:

$$A_n = (A_{n-1} + A_{n+1}) / 2 - C_n$$

Or rearranging:

$$2 A_n = A_{n-1} + A_{n+1} - 2C_n$$

We can use this to solve for An-1:

$$3 A_{n-1} = 2A_{n-2} + A_{n+1} - 2C_n - 4C_{n-1}$$

And so on:

$$4 A_{n-2} = 3A_{n-3} + A_{n+1} - 2C_n - 4C_{n-1} - 6C_{n-2}$$

So at the end we get:

$$(n+1)A_1 = nA_0 + A_{n+1} - 2C_n - 4C_{n-1} - 6C_{n-2} - ... - 2nC_1$$