Story of Hdu 2018 cows

Source: Internet
Author: User

Story of Hdu 2018 cows
Story of cowsTime 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 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;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.