IMPC - 2013-2014 |
Start: Mar.16.2013 at 12:00:00 PM
Finish: Mar.16.2013 at 05:00:00 PM
The contest is finished!
• Contest scoreboard
|
Feedback | If you notice incorrect translations in Contester, please let author know.
|
|
Time limit 2000/4000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb.
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
|
Для отправки решений необходимо выполнить вход.
|