前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >JAVA大数--POJ 1715 大菲波数

JAVA大数--POJ 1715 大菲波数

作者头像
风骨散人Chiam
发布2020-10-28 11:54:35
2040
发布2020-10-28 11:54:35
举报
文章被收录于专栏:CSDN旧文

Problem Description

Fibonacci数列,定义如下: f(1)=f(2)=1 f(n)=f(n-1)+f(n-2) n>=3。 计算第n项Fibonacci数值。

Input

输入第一行为一个整数N,接下来N行为整数Pi(1<=Pi<=1000)。

Output

输出为N行,每行为对应的f(Pi)。

Sample Input

5

1 2 3 4 5 

Sample Output

1 1 2 3 5

代码语言:javascript
复制
import java.math.BigInteger;
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner sca=new Scanner(System.in);
		int n=sca.nextInt();
		BigInteger f[]=new BigInteger[1005];
		f[1]=f[2]=BigInteger.ONE;
		for(int i=3;i<=1000;i++)
		{
			f[i]=f[i-2].add(f[i-1]);
		}
		while(n-->0)
		{
			int tem=sca.nextInt();
			System.out.println(f[tem]);
		}
	}
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/11/07 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档