zoukankan      html  css  js  c++  java
  • UVa 495

      题目大意:计算斐波那契数列的第n项。

      由于结果会很大,要用到大数。开始本来想节省空间的,就没用数组保存,结果超时了...

     1 import java.io.*;
     2 import java.util.*;
     3 import java.math.*;
     4 
     5 class Main
     6 {
     7     public static void main(String args[])
     8     {
     9         Scanner sc = new Scanner(System.in);
    10         BigInteger[] F = new BigInteger[5010];
    11         F[0] = BigInteger.valueOf(0);
    12         F[1] = BigInteger.valueOf(1);
    13         for (int i = 2; i <= 5000; i++)
    14             F[i] = F[i-1].add(F[i-2]);
    15         int n;
    16         while (sc.hasNext())
    17         {
    18             n = sc.nextInt();
    19             System.out.println("The Fibonacci number for " + n +" is " + F[n]);
    20         }
    21     }
    22 }
    View Code
  • 相关阅读:
    InterLockedIncrement and InterLockedDecrement
    bzoj2763
    bzoj1922
    bzoj1705
    bzoj1040
    bzoj3039
    bzoj1801
    bzoj2565
    bzoj1976
    一类最小割bzoj2127,bzoj2132 bzoj3438
  • 原文地址:https://www.cnblogs.com/xiaobaibuhei/p/3346884.html
Copyright © 2011-2022 走看看