Story about cows: 20001000 MS (JavaOthers) & #160; & #160; & #160; & #160; & #6553632768; MemoryLimit: K (JavaOthers) TotalSubmission (s ): 44955 & #160; & #160; & #160; & #160; Accept story
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission (s): 44955 Accepted Submission (s): 22309
Problem Description has a cow. it has a young cow every year. Starting from the fourth year, each calf also gave birth to a calf at the beginning of each year. How many cows are there during the nth year of programming?
The Input data is composed of multiple test instances. each test instance occupies one row and contains an integer n (0 <55),n的含义如题目中描述。
N = 0 indicates the end of the input data without processing.
For each test instance, Output outputs the number of cows in the nth year.
Each output occupies one row.
Sample Input
2450
Sample Output
246
According to the derivation, the number of cows in the nth year is equal to the number of cows in the previous year plus the number of cows in the nth n-3 year (the previous cows started to generate) n = n-1 + n-3
# Include
Using namespace std;
Int fun (int m)
{
If (m> 0 & m <5)
Return m;
Else
Return fun (M-1) + fun (M-3 );
}
Int main ()
{
Int n;
While (cin> n & n)
Cout < <
Return 0;
}
<
<55),n的含义如题目中描述。