您的位置:首页 > 其它

How many Fibs?

2014-04-03 22:58 183 查看
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2321

题意:第一次用java写代码。。纪念一下。。虽然写的有点挫。。

import java.math.BigInteger;
import java.util.Scanner;

public class Main {

public static void main(String[] args) {

Scanner cin = new Scanner(System.in);
while(cin.hasNext()){
int cnt = 0;
BigInteger l = cin.nextBigInteger();
BigInteger r = cin.nextBigInteger();
int t1 = l.compareTo(BigInteger.ZERO);
int t2 = r.compareTo(BigInteger.ZERO);
if (t1==0&&t2==0)
break;
BigInteger f1 = BigInteger.valueOf(1);
BigInteger f2 = BigInteger.valueOf(2);
int s1 = l.compareTo(f1);
int s2 = r.compareTo(f1);
if(s1<=0&&s2>=0)
cnt++;
s1 = l.compareTo(f2);
s2 = r.compareTo(f2);
if(s1<=0&&s2>=0)
cnt++;
while(true)
{
BigInteger f = f1.add(f2);
s1 = l.compareTo(f);
s2 = r.compareTo(f);
if(s1<=0&&s2>=0)
cnt++;
if (s2 < 0)
break;
f1 = f2;
f2 = f;
}
System.out.println(cnt);

}
}

}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: