首页 > 其他 > 详细

大菲波数 (hdu oj 1715 ,java 大数)

时间:2014-02-17 08:11:29      阅读:296      评论:0      收藏:0      [点我收藏+]

大菲波数

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
 
bubuko.com,布布扣
 1 import java.math.BigInteger;
 2 import java.util.Scanner;
 3 
 4 public class A{
 5     public static void main(String[] args) {
 6         Scanner scanner = new Scanner(System.in);
 7         BigInteger fib[] = new BigInteger[100];
 8         fib[1] = new BigInteger("1");
 9         fib[2] = new BigInteger("1");
10         for (int i = 3; i <= 1000; ++i) {
11             fib[i] = fib[i - 1].add(fib[i - 2]);
12         }
13         while (scanner.hasNextInt()) {
14             int t = scanner.nextInt();
15             while (t > 0) {
16                 int i = scanner.nextInt();
17                 System.out.println(fib[i]);
18                 t--;
19             }
20         }
21     }
22 }
bubuko.com,布布扣

 

 

大菲波数 (hdu oj 1715 ,java 大数)

原文:http://www.cnblogs.com/zjutlitao/p/3551673.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!