HDU1250_Hat's Fibonacci【大数】【水题】

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 Fibonacci 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 Fibonacci number in excess of 2005 digits will be in the test data, ie. F(20) = 66526 has 5 digits.

Author

戴帽子的

#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【大数】【水题】

时间: 2024-08-15 20:48:59

HDU1250_Hat's Fibonacci【大数】【水题】的相关文章

HDU-1042-N!(Java大法好 &amp;&amp; HDU大数水题)

N! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 64256    Accepted Submission(s): 18286 Problem Description Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N! Input One N in o

HDU-1047-Integer Inquiry(Java大数水题 &amp;&amp; 格式恶心)

Integer Inquiry Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 14886    Accepted Submission(s): 3811 Problem Description One of the first users of BIT's new supercomputer was Chip Diller. He e

入门训练 Fibonacci数列 (水题)

入门训练 Fibonacci数列 时间限制:1.0s   内存限制:256.0MB 问题描述 Fibonacci数列的递推公式为:Fn=Fn-1+Fn-2,其中F1=F2=1. 当n比较大时,Fn也非常大,现在我们想知道,Fn除以10007的余数是多少. 输入格式 输入包含一个整数n. 输出格式 输出一行,包含一个整数,表示Fn除以10007的余数. 说明:在本题中,答案是要求Fn除以10007的余数,因此我们只要能算出这个余数即可,而不需要先计算出Fn的准确值,再将计算的结果除以10007取余

大数--几道水题,用来学学JAVA

几道水题,练习一下JAVA写大数 poj2305  Basic remains 大数可以直接用非十进制读入,读入的数在变量中是十进制的 输出的时候要先用BigInteger的toString方法转换为相应的进制 1 import java.math.*; 2 import java.util.*; 3 class Main 4 { 5 public static void main(String[] args) 6 { 7 Scanner cin = new Scanner(System.in)

poj水题-1001 一个简单的大数乘幂算法实现

说到底就是一个大数乘幂运算,小数点后零.明白大数乘幂算法直接搞. 这里就有几个问题: 1.幂位数小可以用二进制容器表示(取模更好,但我是为了练习STL) 2.n位大数用string表示,外加一个int型表示小数点位置 3.字符串×字符串用小学竖式乘法算法就行,注意补零.位数多时两个string两个string地加. 代码长,但理解容易,大数乘法,加法函数很多都能重用. 1 #include <iostream> 2 #include <vector> 3 #include <

HDU 4006 The kth great number (基本算法-水题)

The kth great number Problem Description Xiao Ming and Xiao Bao are playing a simple Numbers game. In a round Xiao Ming can choose to write down a number, or ask Xiao Bao what the kth great number is. Because the number written by Xiao Ming is too mu

HDU 5832 A water problem(某水题)

HDU 5832 A water problem(某水题) Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)   Problem Description - 题目描述 Two planets named Haha and Xixi in the universe and they were created with the universe beginning. There is

2015南阳CCPC L - Huatuo&#39;s Medicine 水题

L - Huatuo's Medicine Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description Huatuo was a famous doctor. He use identical bottles to carry the medicine. There are different types of medicine. Huatuo put medicines into the bottles and chain these b

sdut 2841 Bit Problem (水题)

题目 贴这个题是因为看题解有更简单的方法, 我做的时候是直接算的, 也很简单. 贴一下题解吧: 如果一个整数不等于 0,那么该整数的二进制表示中至少有一位是 1. 这个题结果可以直接输出 x - (x&(x-1)); 因为x-1 之后二进制下,就是最右边的1变成了0, 最右边的1的 右边所有的0变成了1, 不影响最左边. 我的代码: 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4