By Ricardo Martins, Instituto Federal do Sul de Minas Gerais Brazil
Nth was fascinated by numerical sequences. He practiced every day to discover new terms of a given sequence, given its initial values, but it took a lot of time to do this. So he needs you to help him by making an algorithm that calculates the nth term of a sequence, given the first three terms of it.
The input consists of several test cases. Each case contains four integer values, the first three being the initial values of a sequence, A, B and C; and the last value is about the nth term to be discovered in this sequence, N.
For each test case, print the nth term of the sequence.
Input Samples | Output Samples |
1 2 3 10000 |
10000 |
11 20 29 6 |
56 |