Java 大数之大数高精度斐波那契 UVA_10579&&HDU1316 How many Fibs?
来源:互联网 发布:手机游戏拍摄软件 编辑:程序博客网 时间:2024/05/21 07:06
UVA_10579
import java.math.BigInteger; import java.util.Scanner; public class UVA_10579 {//fibs[20] = 6765 ,fibs的上限达到上千位 public static void main(String[] args) { Scanner cin = new Scanner(System.in); BigInteger[] fibs = new BigInteger[2000]; fibs[1] = new BigInteger("1"); fibs[2] = new BigInteger("1"); int i; for(i = 3 ; i < 2000 ; ++i){ fibs[i] = fibs[i-1].add(fibs[i-2]); } while(cin.hasNext()){ int n = cin.nextInt(); System.out.println(fibs[n]); } } }
HDU1316
import java.math.BigDecimal; import java.math.BigInteger; import java.util.Scanner; public class Main { public static void main(String []args)throws Exception{ Scanner in = new Scanner(System.in); while(in.hasNext()){ String a=in.next(); String b=in.next(); if(a.equals("0")&&b.equals("0")) break; BigInteger c = new BigInteger(a); BigInteger d = new BigInteger(b); int sum=fibo(c,d); System.out.println(sum); } in.close(); } public static int fibo(BigInteger a,BigInteger b){ int sum =0; BigInteger f = new BigInteger("1"); BigInteger s = new BigInteger("2"); while(true){ if(f.compareTo(b)>0) //前一个数比后一个数大 break; if(f.compareTo(a)>=0) //前一个数比后一个数大或相等 sum++; BigInteger t = f; f=s; s=s.add(t); } return sum; } }
仅代表个人观点,欢迎交流探讨,勿喷~~~
PhotoBy:WLOP
http://weibo.com/wlop
0 0
- Java 大数之大数高精度斐波那契 UVA_10579&&HDU1316 How many Fibs?
- HDU1316:How Many Fibs?(大数JAVA)
- HDU1316 How Many Fibs? 【大数】
- HDU1316 How Many Fibs? 【大数】
- hdu1316 How Many Fibs?(大数)
- hdu1316 How Many Fibs? (java大数练习第二弹)
- How Many Fibs? hdu1316 高精度
- hdu1316(How Many Fibs?)高精度
- How Many Fibs? (大数)
- hdu 1316 How Many Fibs?【JAVA大数】
- How many Fibs?(JAVA)大数
- 【JAVA大数训练】How Many Fibs?
- How many Fibs?(java大数)
- UVA10183 - How Many Fibs?(java大数+二分)
- HDU-1316 How Many Fibs?(Java大数)
- HDU1316:How Many Fibs?
- hdu1316 How Many Fibs?
- hdu1316 How Many Fibs?
- hdu5379(树形dp)
- activiti_二_HelloWprld(非web工程)
- coursera机器学习技法笔记(1-4)——Support Vector Machine
- C++第2次实验作业
- 使用火狐插件 YSLOW
- Java 大数之大数高精度斐波那契 UVA_10579&&HDU1316 How many Fibs?
- Mount挂载命令使用方法
- android onSaveInstanceState方法 横坚屏切换
- MySQL数据库小结---待完善
- NSArray 的大部分用法
- 【湖南集训 4.2】正12面体
- (四)mybatis学习之原始Dao开发方式及与spring整合
- Ruby语言基础学习十:Ruby文件输入输出
- XAudio2学习之混音