HDU 1316 How Many Fibs?(java,简单题,大数)
2020-11-26 15:53
标签:style blog class code java tar ext color get int string 题目 /** HDU 1316 How Many Fibs?(java,简单题,大数),搜素材,soscw.com HDU 1316 How Many Fibs?(java,简单题,大数) 标签:style blog class code java tar ext color get int string 原文地址:http://www.cnblogs.com/laiba2004/p/3702634.html
/**
* compareTo:根据该数值是小于、等于、或大于 val 返回 -1、0 或 1;
public int
compareTo(BigInteger val)
将此 BigInteger 与指定的 BigInteger
进行比较。
对于针对六个布尔比较运算符 (, >=, !=,
中的每一个运算符的各个方法,优先提供此方法。
执行这些比较的建议语句是:(x.compareTo(y)
其中
*/
* and:等同于c++的&&,且;
*/import java.io.*;
import java.util.*;
import java.math.*;
public class Main {
/**
* @xqq
*/
public int an(BigInteger a, BigInteger b, BigInteger sa, BigInteger sb) {
int ans = 0;
if(a.compareTo(sa) >= 0 && a.compareTo(sb) ) {
ans++;
}
if(b.compareTo(sa) >= 0 && b.compareTo(sb) ) {
ans++;
}
for(;;) {
BigInteger c = a.add(b);
a = b;
b = c;
if(b.compareTo(sa) >= 0 && b.compareTo(sb) ) {
ans++;
}
if(b.compareTo(sb) > 0) {
return ans;
}
}
}
public static void main(String[] args) throws Exception {
// 定义并打开输入文件
Scanner cin = new Scanner(System.in);
Main e = new Main();
BigInteger a = BigInteger.valueOf(1);
BigInteger b = BigInteger.valueOf(2);
BigInteger sa;
BigInteger sb;
BigInteger zero = BigInteger.ZERO;
while(cin.hasNext()) {
sa = cin.nextBigInteger();
sb = cin.nextBigInteger();
if(sa.compareTo(zero) == 0 && sb.compareTo(zero) == 0) {
break;
}
System.out.println(e.an(a, b, sa, sb));
}
cin.close(); //关闭输入文件
}
}
文章标题:HDU 1316 How Many Fibs?(java,简单题,大数)
文章链接:http://soscw.com/essay/22673.html