题目

/**
* compareTo:根据该数值是小于、等于、或大于 val 返回 -1、0 或 1;
public int compareTo(BigInteger val)
将此 BigInteger 与指定的 BigInteger 进行比较。
对于针对六个布尔比较运算符 (<, ==, >, >=, !=, <=)
中的每一个运算符的各个方法,优先提供此方法。
执行这些比较的建议语句是:(x.compareTo(y) <op> 0),
其中 <op> 是六个比较运算符之一。
*/

/**
* 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) <= 0) {
ans++;
}
if(b.compareTo(sa) >= 0 && b.compareTo(sb) <= 0) {
ans++;
}
for(;;) {
BigInteger c = a.add(b);
a = b;
b = c;
if(b.compareTo(sa) >= 0 && b.compareTo(sb) <= 0) {
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,简单题,大数)的更多相关文章

  1. HDU 1715 大菲波数(JAVA, 简单题,大数)

    题目 //BigInteger 和 BigDecimal 是在java.math包中已有的类,前者表示整数,后者表示浮点数 import java.io.*; import java.util.*; ...

  2. hdu 1316 How Many Fibs?

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1316 How Many Fibs? Description Recall the definition ...

  3. HDU 4627 The Unsolvable Problem(简单题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4627 题目大意:给定一个整数n(2 <= n <= 109),满足a+b=n并且[a,b] ...

  4. hdu 2114 Calculate S(n) 数论(简单题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2114 自己对数论一窍不通啊现在,做了一道水题,贴出来吧...主要是让自己记住这个公式: 前n项和的立方 ...

  5. HDU 1711 Number Sequence (KMP简单题)

    Number Sequence Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  6. hdu 1316 How many Fibs?(高精度斐波那契数)

    //  大数继续 Problem Description Recall the definition of the Fibonacci numbers:  f1 := 1  f2 := 2  fn : ...

  7. hdu 5455 (2015沈阳网赛 简单题) Fang Fang

    题目;http://acm.hdu.edu.cn/showproblem.php?pid=5455 题意就是找出所给字符串有多少个满足题目所给条件的子串,重复的也算,坑点是如果有c,f以外的字符也是不 ...

  8. HDU 4708 Rotation Lock Puzzle (简单题)

    Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  9. hdu 1253 胜利大逃亡(简单题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1253 题目大意:在所给的时间能顺利离开城堡. #include <iostream> #i ...

随机推荐

  1. next permutaion算法

    算法描述: Find largest index i such that array[i − 1] < array[i]. Find largest index j such that j ≥ ...

  2. rman 命令

    OS: Oracle Linux Server release 5.7 DB: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - ...

  3. Python常用内建模块

    Python常用内建模块 datetime 处理日期和时间的标准库. 注意到datetime是模块,datetime模块还包含一个datetime类,通过from datetime import da ...

  4. 九度oj 1407 快速找出最小数

    原题链接:http://ac.jobdu.com/problem.php?pid=1407 线段树,区间更新,查询区间最小值. 注意区间更新,查询的时候,区间$\begin{align*}[L,R] ...

  5. hive hwi使用

    hwi(hive web interface)是hive命令行接口的补充. 使用方法: 1.配置: 在配置文件hive-site.xml 中,默认有hwi的配置 <property> &l ...

  6. iOS10推送必看UNNotificationServiceExtension

    转:http://www.cocoachina.com/ios/20161017/17769.html (收录供个人学习用) iOS10推送UNNotificationServic 招聘信息: 产品经 ...

  7. 关于1>LINK : fatal error LNK1168: 无法打开 ....exe或者....dll进行写入的问题

      我们用VS编译器运行我们的程序时候,可能会出现关于1>LINK : fatal error LNK1168: 无法打开 ...dll 进行写入或者是1>LINK : fatal err ...

  8. C中的一些函数

    简述:printf.sprintf函数 转载自http://www.cnblogs.com/adslg/archive/2008/08/22/1274164.html 部分进行了修改,参考http:/ ...

  9. 容器适配器之stack

    参见http://www.cplusplus.com/reference/stack/stack/ template<class T, class Container = deque<T& ...

  10. Spring事务总结

    事务是什么? 事务就是用来解决类似问题,事务是一系列的动作,它们综合在一起才是一个完整的工作单元,这些动作必须全部完成,如果有一个失败,那么事务就会回滚到最开始的状态,仿佛什么都没有发生过.在企业级应 ...