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. Java 非对称加密

    package test; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.Object ...

  2. 使用Navicat for Oracle 出现的错误

    错误提示: 意思是不能创建oci环境我们需要对 Navicat for Oracle 做一下配置依此选择 Tools -> Miscellaneous -> OCI OCI library ...

  3. 阿里云服务器(Win 2008 R2 Standard)安装MSSM 2008 R2之1033和2052问题

    最近在给租用的阿里云服务器安装Sql Server 2008 R2 Express时,遭遇下面的问题.经过几番折腾后,终于解决问题,完成安装,这里总结分享我的解决方法,希望能给遇到相同问题的小伙伴们节 ...

  4. OJ的文件流操作

    我们刷题的时候除了编码外,测试也是非常重要的,当测试样例比较小的时候,我们完全可以手打,但是当测试样例比较大时候,我们就抓狂了~ 相信不少人都知道利用文件流,但是应该还有新手跟我一样,一遍又一遍地输入 ...

  5. windows8一直更新不了的问题————解决方案

    以下是微软官方工程师的详细解答: 尊敬的佐先生: 您好! 感谢您联系微软技术支持!我是微软技术支持工程师,我姓张.我将协助您解决有关问题.您的问题编号是SRX 1274238225 对于您当前的更新问 ...

  6. SGU 246. Black & White(数论)

    题意: 有2*n-1个黑色和白色的珠子组成的环形项链,求至少需要多少颗黑色珠子才能使任意排列的项链中都存在两个黑珠间有n个珠子. (2*n-1<=2^31-1); Solution: 先分析n= ...

  7. Data Abstraction

    What is an object? (Page 238) In C++, an object is just a variable, and the purest definition is &qu ...

  8. HDU 5491 The Next

    Problem Description Let L denote the number of 1s in integer D’s binary representation. Given two in ...

  9. Android APK安装过程介绍

    课题路径:从Myfile中点击应用进行安装,到安装完成,过程分析 思想方法:在研究PreloadInstaller的时候我们直接从整个apk的文件结构入手,由整体到部分的分析:但现在整个PMS非常庞大 ...

  10. 【转】mysqldump

    原文地址:http://blog.chinaunix.net/uid-16844903-id-3411118.html 导出 导出全库备份到本地的目录 mysqldump -u$USER -p$PAS ...