Թաքցված խնդիր
|Այս խնդիրը թաքցված է խմբագրական խրհրդի անդամի կողմից քանի որ կամ այն ոչ ճիշտ լեզվով է գրված,|կամ թեստային տվյալներն են սխալ, կամ խնդրի ձևակերպումը պարզ չէ։|

ACM_0063 - 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 first year students at its academy.

   The following sequence of numbers represents how tribbles reproduce. The first number repre- sents generation 0, the second generation 1, and so on.

1, 1, 2, 4, 8, 15, 29, 56

   The following recurrence can be used to represent the above sequence, where n represents the generation number:

n < 2 :

1

n = 2 :

2

n = 3 :

4

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 first 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.

Input

   The first line of input will be an integer t (0 < t < 69) representing the number of test cases. Following this will be t integer values, one per line. Each of these will represent a generation number g (0 ≤ g ≤ 67) to calculate.

Output

   For each generation number read, display the corresponding ‘Tribblenacci’ value.

Examples

stdin

stdout

1

8

0

1

2

3

4

5

30

67

1

1

2

4

8

15

201061985

7057305768232953720


Ավելացրեց.Հրանտ Հովհաննիսյան
Ամսաթիվ.2014-01-03
Ժամանակի սահմանափակումը.1s
Ծրագրի տեքստի սահմանափակումը.50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Լեզուներ.Բոլորը բացի ASM32 ASM64 GAWK CLPS CLOJURE D ERL FSHARP FORTRAN GOSU HASK ICON ICK NEM NIM OBJC-CLANG PICO PIKE PYPY PYPY3 PY_NBC RUST SCM guile CHICKEN SED TCL WHITESPACE
Աղբյուրը.NA Pacific NW 2013.G

© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.