HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Volumes > Winner's Camp > problem:


12. 50723 - Tribonacci

Guest
• Review clarifications (1)

Volume problems

• 51004 - Word Search Game
• 03. 50673 - DNA Testing
• 06. 50714 - The knight
• 12. 50723 - Tribonacci
• 04. 50649 - Puzzle
• 01. 50722 - Scientist's problem
• 02. 50376 - Sequences
• 05. 50713 - Castle and the girls
• 08. 50370 - Number of rectangles in ...
• 09. 50716 - All Palindromes
• 10. 50475 - Voice advertising
• 11. 50476 - Meditation

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