hdu 1250 java大数练习
来源:互联网 发布:黑科技软件 编辑:程序博客网 时间:2024/06/02 04:17
Problem Description
A Fibonacci sequence is calculated by adding the previous two members the sequence, with the first two members being both 1.
F(1) = 1, F(2) = 1, F(3) = 1,F(4) = 1, F(n>4) = F(n - 1) + F(n-2) + F(n-3) + F(n-4)
Your task is to take a number as input, and print that Fibonacci number.
Input
Each line will contain an integers. Process to end of file.
Output
For each case, output the result in a line.
Sample Input
100
Sample Output
4203968145672990846840663646
Note:
No generated Fibonacci number in excess of 2005 digits will be in the test data, ie. F(20) = 66526 has 5 digits.
题解:
java大数。注意提交的时候把类改为Main,不然每次都出错。
代码:
import java.math.BigInteger;import java.util.Scanner;public class HatsFibonacci { public static void main(String[] args) { // TODO Auto-generated method stub Scanner in = new Scanner(System.in); BigInteger num[] = new BigInteger[10000]; num[1] = BigInteger.ONE; num[2] = BigInteger.ONE; num[3] = BigInteger.ONE; num[4] = BigInteger.ONE; while(in.hasNext()) { int n = in.nextInt(); for(int i=5;i<=n;i++) { num[i] = num[i-1].add(num[i-2]).add(num[i-3]).add(num[i-4]); } System.out.println(num[n]); } } }
阅读全文
0 0
- hdu 1250 java大数练习
- hdu-5429(大数java练习)
- JAVA大数高精度练习
- java大数练习
- 【java 大数】hdu java 大数
- hdu 1250 hdu 1130 java水大数
- hdu 1250 Hat's Fibonacci(java大数)
- HDU 1250 Hat's Fibonacci (JAVA大数)
- HDU 1250 Hat's Fibonacci JAVA大数
- Java大数练习第一弹
- Java大数练习第二弹
- JAVA大数练习第三弹
- hdu 4873 Java大数
- hdu 4919 java大数
- hdu 4927 java大数
- HDU-5050 java大数
- HDU-1042(java 大数)
- hdu 2045 java 大数
- 《古月ROS探索总结》学习笔记1
- C#面向对象、构造器简单总结
- day47_linux软件安装&Redis入门---总结
- ubuntu系统github上传本地项目
- MySQL的MyISAM和InnoDB的区别
- hdu 1250 java大数练习
- AndroidUI_ListView
- PowerBuilder 调用http接口
- 【2017广西邀请赛】hdu 6185 Covering 矩阵快速幂
- 如果编程语言是女人,你会爱上谁?
- 微信小程序------轮播图
- java SwingUtilities.getAncestorOfClass(Class c,Component comp)的用法
- HDU 4786 Fibonacci Tree
- 12C RAC环境节点宕机问题