HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Sections > Recursion > problem:


50723 - Tribonacci

Guest
• Review clarifications (1)

Section problems

• 50723 - Tribonacci
• 50370 - Number of rectangles in a ...
• 50475 - Voice advertising
• 50909 - Gold Coins
• 50376 - Sequences
• 50725 - Fibonacci Series
• 50385 - The 3n + 1 problem
• 50911 - Symmetric Array
• 50381 - Sum of the numbers

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


Для отправки решений необходимо выполнить вход.

www.contester.ru