HDU - 1250-大数加法

题目传送门

HDU - 1250
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.

package dashu;
import java.math.BigInteger;
import java.util.Scanner;
public class da{
   
	public static void main(String[] aegs)
	{
   
		int n;
		Scanner in=new Scanner(System.in);
		BigInteger th[]=new BigInteger[10010];
		BigInteger w=new BigInteger("1");
		th[1]=th[2]=th[3]=th[4]=w;
		for(int i=5;i<=10000;i++)
		{
   
			th[i]=th[i-1].add((th[i-2].add(th[i-3].add(th[i-4]))));
		}
		while(in.hasNext())
		{
   
			n=in.nextInt();
			System.out.println(th[n]);
		}
	}
}
全部评论

相关推荐

SHC2:春招先狠狠投递,然后你看看能不能申请香港新加坡的一年制master,花不了多少钱,或者现在赶紧去刷一段实习。HR专业考研没必要
点赞 评论 收藏
分享
老板加个卤鸡蛋:HR看了以为来卧底来了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
正在热议
更多
# 一张图晒出你司的标语 #
4401次浏览 77人参与
# 找AI工作可以去哪些公司? #
9509次浏览 255人参与
# 厦门银行科技岗值不值得投 #
8146次浏览 188人参与
# 你的实习产出是真实的还是包装的? #
20514次浏览 343人参与
# AI面会问哪些问题? #
28438次浏览 572人参与
# 春招至今,你的战绩如何? #
66746次浏览 588人参与
# 开放七大实习专项,百度暑期实习值得冲吗 #
15486次浏览 223人参与
# 从事AI岗需要掌握哪些技术栈? #
9382次浏览 329人参与
# 中国电信笔试 #
32126次浏览 295人参与
# 你做过最难的笔试是哪家公司 #
34705次浏览 253人参与
# 投递几十家公司,到现在0offer,大家都一样吗 #
341033次浏览 2175人参与
# 金三银四,你的春招进行到哪个阶段了? #
22379次浏览 284人参与
# 同bg的你秋招战况如何? #
212250次浏览 1121人参与
# 哪些公司真双非友好? #
69755次浏览 289人参与
# 如何准备秋招 #
78315次浏览 868人参与
# 阿里笔试 #
179152次浏览 1318人参与
# 机械人避雷的岗位/公司 #
62713次浏览 393人参与
# 小马智行求职进展汇总 #
25149次浏览 80人参与
# 第一份工作一定要去大厂吗 #
14992次浏览 122人参与
# 担心入职之后被发现很菜怎么办 #
291406次浏览 1210人参与
# 为了减少AI幻觉,你注入过哪些设定? #
26297次浏览 310人参与
# 应届生第一份工资要多少合适 #
20707次浏览 86人参与
牛客网
牛客网在线编程
牛客网题解
牛客企业服务