How many Fibs?
2014-04-03 22:58
183 查看
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2321
题意:第一次用java写代码。。纪念一下。。虽然写的有点挫。。
View Code
题意:第一次用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
相关文章推荐
- c++跨平台开发经验
- You Win! 状态压缩dp
- Scramble String
- 清明雨纷,且容我思念
- Path Sum II
- struts2后台写cookie,前台读jquery读cookie
- Java获取当前的年月
- Struts2中的动态链接标签--->动态传值【转】
- IPv4 + NAT
- Java获取当前的年月
- 严蔚敏 数据结构 课本中 栈应用 走迷宫 C语言 完整版
- 华丽转身——浅识J2EE十三标准
- hdu 1000 A + B Problem
- java 基于Struts2的 文件上传和下载
- C/C++中各种类型int、long、double、char表示范围(最大最小值)
- 【LeetCode OJ】LRU Cache
- jQuery代码的编写---1.3.3: jQuery代码风格
- ASP.NET Identity登录原理 - Claims-based认证和OWIN
- hdu1753大明A+B
- OpenStack最新版本Folsom架构解析(2)