|
Лимит времени 2000/4000/4000/4000 мс. Лимит памяти 65000/65000/65000/65000 Кб.
Tribonacci
Montenegro Informatics Olympiads 2013
Question:
Tribonacci sequence is obtained by the following formula:
Tn = Tn-1 + Tn-2 + Tn-3
for a given N and three first elements of the sequence, the formula computes
the N-th element of the Tribonacci. Write a program that gets
four integers T1, T2, T3 and N.
Then the program computes N-th element of the sequence.
Input specification
The input has only one line consisting of 4
integers T1, T2,
T3 and N separated by a space
where 1 ≤ N ≤ 20 and -20000 ≤
(T1, T2, T3) ≤ 20000.
Output specification
Print the N-th element of the sequence.
Sample Input I
2 3 4 5
|
Sample Input II
1 1 1 6
|
Sample Output I
16
|
Sample Output II
9
|
Для отправки решений необходимо выполнить вход.
|