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

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

 import java.io.*;
import java.util.*;
import java.math.*; class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
BigInteger[] F = new BigInteger[5010];
F[0] = BigInteger.valueOf(0);
F[1] = BigInteger.valueOf(1);
for (int i = 2; i <= 5000; i++)
F[i] = F[i-1].add(F[i-2]);
int n;
while (sc.hasNext())
{
n = sc.nextInt();
System.out.println("The Fibonacci number for " + n +" is " + F[n]);
}
}
}

UVa 495 - Fibonacci Freeze的更多相关文章

  1. UVa 495【大数加法】

    UVa 495 求第n位斐波那契数列,n<=5000. 还是大数问题,这次是大数加法.仿照UVa 623的解法来做.623位数可以一位一位的增,但是这个需要预先给够位数,要是按六位存一个数组元素 ...

  2. Uva 10334

    UVa 10334 这道题几乎和UVa 495是一样的. #include<iostream> #include<cstdio> #define mod 1000000 usi ...

  3. Colossal Fibonacci Numbers! UVA 11582 寻找循环节

    /** 题目:Colossal Fibonacci Numbers! UVA 11582 链接:https://vjudge.net/problem/UVA-11582 题意:f[0] = 1, f[ ...

  4. UVA 12333 Revenge of Fibonacci

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  5. UVa #11582 Colossal Fibonacci Numbers!

    巨大的斐波那契数 The i'th Fibonacci number f (i) is recursively defined in the following way: f (0) = 0 and  ...

  6. 数论 - 高精度Fibonacci数 --- UVa 10183 : How Many Fibs ?

    How many Fibs? Description Recall the definition of the Fibonacci numbers: f1 := 1 f2 := 2 fn := f n ...

  7. Colossal Fibonacci Numbers(巨大的斐波那契数)UVA 11582

    评测地址:http://acm.hust.edu.cn/vjudge/problem/41990 The i'th Fibonacci number f (i) is recursively de n ...

  8. POJ-3070Fibonacci(矩阵快速幂求Fibonacci数列) uva 10689 Yet another Number Sequence【矩阵快速幂】

    典型的两道矩阵快速幂求斐波那契数列 POJ 那是 默认a=0,b=1 UVA 一般情况是 斐波那契f(n)=(n-1)次幂情况下的(ans.m[0][0] * b + ans.m[0][1] * a) ...

  9. UVA 11582 Colossal Fibonacci Numbers(数学)

    Colossal Fibonacci Numbers 想先说下最近的状态吧,已经考完试了,这个暑假也应该是最后刷题的暑假了,打完今年acm就应该会退了,但是还什么都不会呢? +_+ 所以这个暑假,一定 ...

随机推荐

  1. NYOJ 925 国王的烦恼

    从最后一天开始往前加边. 同一天的边同时加到图上,加完之后检查集合数量是否和没加之前有变化. 有变化的话,答案就+1. #include<cstdio> #include <iost ...

  2. PAT (Advanced Level) 1112. Stucked Keyboard (20)

    找出一定没问题的字符(即一连串的额字符x个数能被k整除的),剩下的字符都是可能有问题的. #include<cstdio> #include<cstring> #include ...

  3. PAT (Advanced Level) 1102. Invert a Binary Tree (25)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  4. 关于VC中的错误处理

    include <exception> try {} cache(exception &e) { cout<<e.what()<<endl; }     但 ...

  5. linux下如何修改iptables开启80端口

    linux下如何修改iptables开启80端口   最近在做本地服务器的环境,发现网站localhost能正常访问,用ip访问就访问不了,经常使用CentOS的朋友,可能会遇到和我一样的问题.开启了 ...

  6. Ubuntu 12.04 怎样安装 Google Chrome

    方法一: http://www.360doc.com/content/14/0723/19/4338_396584130.shtml 方法2: How to Install Google Chrome ...

  7. FusionCharts 分类以及各个属性参数列表

    <FusionCharts学习及使用笔记>之 第一篇 其实一直以来我都在有意无意的把我平常工作中遇到并解决的问题做个记录,放到我的网易博客中.但却一直没有想过如何把我使用的技术做一个系列化 ...

  8. 超级素数(sprime)

    超级素数(sprime) 题目描述 超级素数是指一个素数,每去掉后面一个数字,总能保证剩下的数为质数,例如:373->37->3这是一个长为3的超级素数. 输入 输入一个整数n (10≤n ...

  9. 使用jquery模拟键盘事件,但window系统并不会真的响应事件,只是浏览器当前页面会响应而已

    <!DOCTYPE html> <html> <head> <title>Demo</title> <meta http-equiv= ...

  10. Activity与Service之间交互并播放歌曲的实现代码

    Activity与Service之间交互并播放歌曲,为了方便,我把要播放的歌曲定死了,大家可以灵活改进 MService: 复制代码代码如下: package com.tiantian.test;im ...