Hdu1250_hat's Fibonacci [large number] [water question]

Source: Internet
Author: User
Hat's Fibonacci

Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/others) total submission (s): 7854 accepted submission (s): 2551
Problem description
A Fibonacci sequence is calculated by adding the previous two members the sequence, with the first two members being both 1.
F (1) = 1, F (2) = 1, F (3) = 1, F (4) = 1, F (n> 4) = f (n-1) + f (n-2) + f (n-3) + f (n-4)
Your task is to take a number as input, and print that maid number.

Input
Each line will contain an integers. process to end of file.
 
Output
For each case, output the result in a line.
 
Sample Input
100
 
Sample output
4203968145672990846840663646

Note:
No generated Maid number in excess of 2005 digits will be in the test data, ie. F (20) = 66526 has 5 digits.
 
Author

Wearing a hat

#include<stdio.h>#include<string.h>int f1[2050],f2[2050],f3[2050],f4[2050],f5[2050];int main(){    int N;    while(~scanf("%d",&N))    {        if(N==1)            printf("1\n");        else if(N==2)            printf("1\n");        else if(N==3)            printf("1\n");        else if(N==4)            printf("1\n");        else        {            memset(f1,0,sizeof(f1));            memset(f2,0,sizeof(f2));            memset(f3,0,sizeof(f3));            memset(f4,0,sizeof(f4));            memset(f5,0,sizeof(f5));            f1[0] = f2[0] = f3[0] = f4[0] = 1;            for(int i = 5; i<= N; i++)            {                for(int j = 0; j <= 2010; j++)                {                    f5[j] = f1[j] + f2[j] + f3[j] + f4[j];                    if(f5[j] >= 10)                    {                        f1[j+1] += (f5[j]/10);                        f5[j] = (f5[j]%10);                    }                    f1[j] = f2[j];                    f2[j] = f3[j];                    f3[j] = f4[j];                    f4[j] = f5[j];                }            }            int j;            for(j = 2010; j >= 0; j--)                if(f5[j]!=0)                    break;            for(int i = j; i >= 0; i--)                printf("%d",f5[i]);            printf("\n");        }    }    return 0;}


Hdu1250_hat's Fibonacci [large number] [water question]

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.