eolymp
bolt
Try our new interface for solving problems
Məsələlər

Generations of Tribbles

Generations of Tribbles

Tribbles are the cute, fuzzy, cuddly animals that have voracious appetites and reproduction rates that rival any complex organism in the galaxy (tribbles are born pregnant!). After being introduced to the Enterprise and its crew, it was quickly discovered what a nuisance tribbles could be. In a very short amount of time, tribbles were everywhere on the ship. Fortunately for the Enterprise, Engineer Scott was able to transport them to a nearby Klingon vessel. The Klingons were unaware of the issues tribbles could cause and brought them into Klingon space, where the tribbles spread like locusts and devastated ecosystems of planets across the Klingon Empire. Members of the United Federations of Planets (The Federation) found this extremely amusing and used the calculation of tribble reproduction as an academic exercise for rst year students at its academy. The following sequence of numbers represents how tribbles reproduce. The first number represents generation \textbf{0}, the second generation \textbf{1}, and so on. \textbf{1, 1, 2, 4, 8, 15, 29, 56} The following recurrence can be used to represent the above sequence, where \textbf{n} represents the generation number: \textbf{n < 2 : 1} \textbf{n = 2 : 2} \textbf{n = 3 : 4} \textbf{n > 3 : gen(n-1) + gen(n-2) + gen(n-3) + gen(n-4)} Those at the academy that know something about old Earth history have jokingly called the recurrence 'Tribblenacci'. Your job as a rst year student at the academy is to accurately and rapidly calculate how many tribbles there will be for a given 'Tribblenacci' number. The fact is, evaluating the above recurrence recursively is slower than chemical propulsion for interstellar travel! To do so for more than a handful of generations would clearly be illogical. \InputFile The first line of input will be an integer \textbf{t} (\textbf{0} < \textbf{t} < \textbf{69}) representing the number of test cases. Following this will be \textbf{t }integer values, one per line. Each of these will represent a generation number \textbf{g} (\textbf{0} ≤ \textbf{g} ≤ \textbf{67}) to calculate. \OutputFile For each generation number read, display the corresponding 'Tribblenacci' value.
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
8
0
1
2
3
4
5
30
67
Çıxış verilənləri #1
1
1
2
4
8
15
201061985
7057305768232953720
Mənbə 2013 Pacific Northwest Region Programming Contest