加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

UVa:10862 Connect the Cable Wires(斐波那契数列大数)

发布时间:2020-12-14 03:40:57 所属栏目:大数据 来源:网络整理
导读:思路:输出斐波那契数列的第2*n项即可。需要用大数。Java秒杀之。。 import java.util.*;import java.io.*;import java.math.BigInteger; public class Main {public static void main(String[] args) {BigInteger[] f=new BigInteger [4005];f[0]=new BigIn

思路:输出斐波那契数列的第2*n项即可。需要用大数。Java秒杀之。。

import java.util.*;
import java.io.*;
import java.math.BigInteger; 

public class Main 
{
	public static void main(String[] args) 
	{
		BigInteger[] f=new BigInteger [4005];
		f[0]=new BigInteger("0");
	    	f[1]=new BigInteger("1");
	    	for(int i=2;i<=4000;++i)
	    		f[i]=f[i-1].add(f[i-2]);       
        Scanner in = new Scanner(System.in);
        while(in.hasNextInt())
        {
        	int n = in.nextInt(); 
        	if(n==0) break;
            System.out.println(f[2*n]);  
        }
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读