zoukankan      html  css  js  c++  java
  • HDOJ1715 斐波那契[大数水题]

    大菲波数

    Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 6385    Accepted Submission(s): 2083


    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
     
    Source
     
    Recommend
    lcy
     
     
     
    code:
     1 import java.util.*;
     2 import java.math.*;
     3 public class Main
     4 {
     5     public static void main(String []args)
     6     {
     7         Scanner cin=new Scanner(System.in);
     8         BigInteger []data=new BigInteger[1001];
     9         data[1]=BigInteger.valueOf(1);
    10         data[2]=BigInteger.valueOf(1);
    11         int i,j;
    12         int n;
    13         for(i=3;i<1001;i++)
    14             data[i]=data[i-1].add(data[i-2]);
    15         while(cin.hasNext())
    16         {
    17             n=cin.nextInt();
    18             for(i=0;i<n;i++)
    19             {
    20                  j=cin.nextInt();
    21                  System.out.println(data[j]);
    22             }
    23         }
    24     }
    25 }






                If you have any questions about this article, welcome to leave a message on the message board.



    Brad(Bowen) Xu
    E-Mail : maxxbw1992@gmail.com


  • 相关阅读:
    解决Qt creator无法输入中文
    JSP 问题总结
    oracle锁与死锁概念,阻塞产生的原因以及解决方案
    QT学习记录
    使用函数式接口
    使用函数式接口来传递行为
    Prototype(原型)
    Singleton(单例)
    Factory
    Template
  • 原文地址:https://www.cnblogs.com/XBWer/p/2598616.html
Copyright © 2011-2022 走看看