Hat's Fibonacci

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10568    Accepted Submission(s): 3507

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
戴帽子的
 
Recommend
Ignatius.L
#include <iostream>
#include <stdio.h>
using namespace std;
int a[][]={};
int main()
{
int i,j,n;
a[][]=;
a[][]=;
a[][]=;
a[][]=;
for(i=;i<;i++)
{
for(j=;j<;j++)
{
a[i][j]+=a[i-][j]+a[i-][j]+a[i-][j]+a[i-][j];
a[i][j+]+=a[i][j]/;
a[i][j]=a[i][j]%;
}
}
while(cin>>n)
{
for(j=;j>=;j--)
if(a[n][j]!=)
break;
cout<<a[n][j];
for(j=j-;j>=;j--)
printf("%08d",a[n][j]); //不能直接cout 数大的时候是错的 因为可能会输出七位 正常应该输出八位的 反正就是不对
cout<<endl;
}
return ;
}

HDU1250 高精度斐波那契数列的更多相关文章

  1. [luogu2144][bzoj1002][FJOI2007]轮状病毒【高精度+斐波那契数列+基尔霍夫矩阵】

    题目描述 轮状病毒有很多变种,所有轮状病毒的变种都是从一个轮状基产生的.一个N轮状基由圆环上N个不同的基原子和圆心处一个核原子构成的,2个原子之间的边表示这2个原子之间的信息通道.如下图所示 N轮状病 ...

  2. 剑指Offer - 九度1387 - 斐波那契数列

    剑指Offer - 九度1387 - 斐波那契数列2013-11-24 03:08 题目描述: 大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项.斐波那契数列的定义如下: ...

  3. 纪中23日c组T3 2161. 【2017.7.11普及】围攻 斐波那契数列

    2161. 围攻 (File IO): input:siege.in output:siege.out 时间限制: 1000 ms  空间限制: 262144 KB  具体限制   Goto Prob ...

  4. 使用高精度计算斐波那契数列 c++

    使用高精度计算斐波那契数列 非高精度 Code(Non-high accuracy) 这是不用高精度的代码 #include<bits/stdc++.h> using namespace ...

  5. C#求斐波那契数列第30项的值(递归和非递归)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  6. 斐波拉契数列加强版——时间复杂度O(1),空间复杂度O(1)

    对于斐波拉契经典问题,我们都非常熟悉,通过递推公式F(n) = F(n - ) + F(n - ),我们可以在线性时间内求出第n项F(n),现在考虑斐波拉契的加强版,我们要求的项数n的范围为int范围 ...

  7. js中的斐波那契数列法

    //斐波那契数列:1,2,3,5,8,13…… //从第3个起的第n个等于前两个之和 //解法1: var n1 = 1,n2 = 2; for(var i=3;i<101;i++){ var ...

  8. 剑指Offer面试题:8.斐波那契数列

    一.题目:斐波那契数列 题目:写一个函数,输入n,求斐波那契(Fibonacci)数列的第n项.斐波那契数列的定义如下: 二.效率很低的解法 很多C/C++/C#/Java语言教科书在讲述递归函数的时 ...

  9. 算法: 斐波那契数列C/C++实现

    斐波那契数列: 1,1,2,3,5,8,13,21,34,....     //求斐波那契数列第n项的值 //1,1,2,3,5,8,13,21,34... //1.递归: //缺点:当n过大时,递归 ...

随机推荐

  1. 左偏树(DP)问题

    问题:A straight dirt road connects two fields on FJ's farm, but it changes elevation more than FJ woul ...

  2. HDU1907 John

    Description Little John is playing very funny game with his younger brother. There is one big box fi ...

  3. HDU2222 Keywords Search [AC自动机模板]

    Keywords Search Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others ...

  4. java连接mysql(二)

    模拟转账成功时的业务场景 import java.sql.*; public class TransactionDemo1 { public static void main(String[] arg ...

  5. 根据.MDF文件查看 SQL数据库的版本信息

    http://www.cnblogs.com/eason-chan/p/3695753.html?utm_source=tuicool 手上有 经理带来的一个教学管理系统,由于不知道开发环境,在向SQ ...

  6. eclipse下环境变量设置:eclipse导入工程出现 Unbound classpath variable Error

    在导入网友提供的Tomcat源码工程时候出现了 The project cannot be build until build path errors are resolved Unbound cla ...

  7. Servlet之Filter详细讲解

    Filter,过滤器,顾名思义,即是对数据等的过滤,预处理过程.为什么要引入过滤器呢?在平常访问网站的时候,有时候发一些敏感的信息,发出后显示时 就会将敏感信息用*等字符替代,这就是用过滤器对信息进行 ...

  8. 【wget】一条命令轻松备份博客(包括图片)

    h2:first-child, body>h1:first-child, body>h1:first-child+h2, body>h3:first-child, body>h ...

  9. Android Studio-AndroidStudio目录结构

    最近,Google已经打算废弃Eclipse,而要大力支持他的亲生儿子AndroidStudio了,已经不在维护Eclipse了,也就是说在Eclipse上面出了什么问题,Google已经不在会管了, ...

  10. TortoiseGit-创建分支、合并分支

    第一步:创建本地分支 点击右键选择TortoiseGit,选择Create Branch-,在Branch框中填写新分支的名称(若选中"switch to new branch"则 ...