HDOJ/HDU 1250 Hat's Fibonacci(大数~斐波拉契)
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(大数~斐波拉契)的更多相关文章
- 2019牛客暑期多校训练营(第九场)A:Power of Fibonacci(斐波拉契幂次和)
题意:求Σfi^m%p. zoj上p是1e9+7,牛客是1e9: 对于这两个,分别有不同的做法. 前者利用公式,公式里面有sqrt(5),我们只需要二次剩余求即可. 后者mod=1e9,5才 ...
- How many Fibs?(poj 2413)大数斐波那契
http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=259#problem/C Description Recall the defi ...
- 关于斐波拉契数列(Fibonacci)
斐波那契数列指的是这样一个数列 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233,377,610,987,1597,2584,4181,6765,10 ...
- 10、end关键字和Fibonacci series: 斐波纳契数列
# Fibonacci series: 斐波纳契数列 # 两个元素的总和确定了下一个数 a, b = 0, 1 #复合赋值表达式,a,b同时赋值0和1 while b < 10: print(b ...
- python的生成器(斐波拉契数列(Fibonacci))
代码: 函数版本: #斐波拉契数列(Fibonacci) def fib(max): n=0 a,b=0,1 while n < max: a,b = b,a+b n = n+1 return ...
- HDU.2516 取石子游戏 (博弈论 斐波那契博弈)
HDU.2516 取石子游戏 (博弈论 斐波那契博弈) 题意分析 简单的斐波那契博弈 博弈论快速入门 代码总览 #include <bits/stdc++.h> #define nmax ...
- Go斐波拉契数列(Fibonacci)(多种写法)
1 前言 斐波拉契数列有递归写法和尾递归和迭代写法. 2 代码 //recursion func fib(n int) int{ if n < 2{ return n }else{ return ...
- hdu 5914(斐波拉契数列)
Triangle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Su ...
- HDU-4794:Arnold(斐波拉契循环节 二次剩余)
本题我只是个搬运工,主要是抢救补板子,所以自己就没写.https://blog.csdn.net/u013534123/article/details/78058997 题意: 大致题意是给你一个N* ...
随机推荐
- 一封给“X教授”的回信(讨论Socket通信)
转载:http://www.cnblogs.com/tianzhiliang/archive/2011/03/02/1969187.html 前几天"X教授"发Email与我讨论S ...
- Java 非对称加密
package test; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.Object ...
- mvc5 + ef6 + autofac搭建项目(repository+uow)(二)
续上篇: DBContext 在上篇 图一类库根目录创建的 DbContextBase /// <summary> /// 数据库上下文基类 /// </summary> // ...
- MyBatis的学习总结三:优化MyBatis配置文件中的配置
一.优化Mybatis配置文件conf.xml中数据库的信息 1.添加properties的配置文件,存放数据库的信息:mysql.properties具体代码: driver=com.mysql.j ...
- MyEclipse中配置自己的JRE和tomcat
MyEclipse中配置自己的JRE:windows>Preference>java>Installed JREs>Add>Stantard VM>next> ...
- Oracle 11g服务
成功安装Oracle 11g后,共有7个服务, 这七个服务的含义分别为: 1. Oracle ORCL VSS Writer Service: Oracle卷映射拷贝写入服务,VSS(Volume S ...
- C++primer(第五版)读书笔记&习题解答---CHAPTER 3
C++标准库类型包括:string,vector和迭代器,其中string是可变长的字符序列,vector存放的是某种给定类型对象的可变长序列,迭代器是string和vector的配套类型,常被用于访 ...
- demo_05HTML5+CSS3绘制小鸟
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- python调用java
这么个标题多少有点蛋疼的感觉,两个都是互联网时代的语言,学习成本和执行效率也差不多,之所以会产生这种需求,多半是想在python中引用java的类,例如安卓和hadoop的生态圈,基本是java代码的 ...
- 趣味C程序100.1 .1 绘制余弦曲线
说明:1.本问题来源于<C语言经典.趣味.实用程序设计编程百例精解>,所有程序为本人自己编写.与原程序不同之处作有标记. 2.本系列所有程序均使用codeblocks编译,操作系统为Win ...