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.

就是根据这个公式:

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)

输入一个n,输出f(n)的值。

注意,这是大数~答案的位数高达2005位~~~

再一次体会Java大数的强大吧~

import java.math.BigInteger;
import java.util.Scanner; public class Main {
static BigInteger f[] = new BigInteger[7045];
public static void main(String[] args) {
dabiao();
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int n =sc.nextInt();
System.out.println(f[n]);
//System.out.println("---------");
//System.out.println(f[n].toString().length());
//开数组~看开到多少位的时候,位数大于2005
}
}
private static void dabiao() {
f[1]=new BigInteger("1");
f[2]=new BigInteger("1");
f[3]=new BigInteger("1");
f[4]=new BigInteger("1");
for(int i=5;i<f.length;i++){
f[i]=f[i-1].add(f[i-2]).add(f[i-3]).add(f[i-4]);
}
}
}

HDOJ/HDU 1250 Hat's Fibonacci(大数~斐波拉契)的更多相关文章

  1. 2019牛客暑期多校训练营(第九场)A:Power of Fibonacci(斐波拉契幂次和)

    题意:求Σfi^m%p. zoj上p是1e9+7,牛客是1e9:  对于这两个,分别有不同的做法. 前者利用公式,公式里面有sqrt(5),我们只需要二次剩余求即可.     后者mod=1e9,5才 ...

  2. How many Fibs?(poj 2413)大数斐波那契

    http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=259#problem/C Description Recall the defi ...

  3. 关于斐波拉契数列(Fibonacci)

    斐波那契数列指的是这样一个数列 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233,377,610,987,1597,2584,4181,6765,10 ...

  4. 10、end关键字和Fibonacci series: 斐波纳契数列

    # Fibonacci series: 斐波纳契数列 # 两个元素的总和确定了下一个数 a, b = 0, 1 #复合赋值表达式,a,b同时赋值0和1 while b < 10: print(b ...

  5. python的生成器(斐波拉契数列(Fibonacci))

    代码: 函数版本: #斐波拉契数列(Fibonacci) def fib(max): n=0 a,b=0,1 while n < max: a,b = b,a+b n = n+1 return ...

  6. HDU.2516 取石子游戏 (博弈论 斐波那契博弈)

    HDU.2516 取石子游戏 (博弈论 斐波那契博弈) 题意分析 简单的斐波那契博弈 博弈论快速入门 代码总览 #include <bits/stdc++.h> #define nmax ...

  7. Go斐波拉契数列(Fibonacci)(多种写法)

    1 前言 斐波拉契数列有递归写法和尾递归和迭代写法. 2 代码 //recursion func fib(n int) int{ if n < 2{ return n }else{ return ...

  8. hdu 5914(斐波拉契数列)

    Triangle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Su ...

  9. HDU-4794:Arnold(斐波拉契循环节 二次剩余)

    本题我只是个搬运工,主要是抢救补板子,所以自己就没写.https://blog.csdn.net/u013534123/article/details/78058997 题意: 大致题意是给你一个N* ...

随机推荐

  1. 关于word-break,word-wrap换行

    目前项目中有一些流程日志需要动态显示到页面上,实现方法是ajax动态获取附加到<span></span>标签上,然后设置word-break:break-all样式使其自动换行 ...

  2. JavaScript的push(),pop(),concat()方法

    push 方法 将新元素添加到一个数组中,并返回数组的新长度值. arrayObj.push([item1 [item2 [. . . [itemN ]]]]) 参数 arrayObj 必选项.一个  ...

  3. winpcap 发送接收速率

    总体情况: 在不修改winpcap源码的情况下,发包.收包最大速率3包/ms. 收包几个api的速率: 1. m_fp = pcap_open_live(adapter->name, 65536 ...

  4. 理解MySQL——索引与优化(转)

    写 在前面:索引对查询的速度有着至关重要的影响,理解索引也是进行数据库性能调优的起点.考虑如下情况,假设数据库中一个表有10^6条记录,DBMS的页 面大小为4K,并存储100条记录.如果没有索引,查 ...

  5. 去掉Visual Studio 编辑器里中文注释的红色波浪线 转载

    我们通常用visual studio进行开发的时候,我们通常会用到一款比较流行比较方便的插件,那就是Visual Assist X,它可以增强Microsoft开发环境下的编辑能力,支持C/C++,C ...

  6. Sizzle引擎执行的流程图

    Sizzle有太多都不是太懂,但能看懂这张图. 图片来源: http://www.cnblogs.com/aaronjs/p/3332805.html

  7. GoJS研究,简单图表制作。

    话不多说,先上图 我在这个中加入了缩略图.鼠标放大缩小等功能. <!doctype html> <html> <head> <title>Flowcha ...

  8. js中的prototye

    前言 没事的时候写着js完,一般可能大家都知道这个属性吧,但是我还要说说,给一些不知道的人看看吧, 希望对你有帮助. 过程 以前在学c#的时候,老师最多用的就是Person这个类来开讲,我觉得是这个更 ...

  9. centos 7.0防火墙导致vagrant端口映射失败

    在vagrant上部署了centos7.0后,Vagrantfile端口转发设置后,宿主机访问客户机站点还是无法访问,问题出在:centos7.0以上版本默认会安装firewalld防火墙, fire ...

  10. crontab 基本用法

    crontab格式:第1列分钟1-59第2列小时1-23(0表示子夜)第3列日1-31第4列月1-12第5列星期0-6(0表示星期天)第6列要运行的命令 还可以用一些特殊符号: *: 表示任何时刻 , ...