Q 1004: [Recursive] The story of the cow
Time limit: 1Sec Memory Limit: 128MB
Title Description
There is a cow that gives birth to a heifer at the beginning of each year. Each heifer also gives birth to one heifer at the beginning of each year, starting from the fourth year. Program how many heifers are there in year n?
Input
The input data consists of multiple test instances, each of which occupies one line and includes an integer n (0<n<55), with n meaning as described in the title. n=0 indicates the end of the input data and is not processed.
Output
For each test instance, the number of cows at year n is output. Each output occupies one line.
Sample Input
2 4 5 0
Sample Output
2 4 6
C Code
Solution A
|
|
Solution B
|
|