题目

/**
* 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. spring debug

    DispatcherServlet{ getHandler()}handlerMappings{ RequestMappingHandlerMapping BeanNameUrlHandlerMapp ...

  2. linux kernel 0.11 setup

    setup作用 ①读取参数放在0x90000处. ②将原本在0x10000处的system模块移至0x00000处 ③加载中断描述符表,全局描述符表,进入32位保护模式. 概念 关于实模式和保护模式区 ...

  3. js实现对身份证校验

    var vcity={ 11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古&quo ...

  4. uninstall 11.2.0.3.0 grid & database in linux 5.7

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

  5. 6月24日AppCan移动开发者大会礼品清单遭泄露

    6月24日,第一届AppCan移动开发者大会将在北京国际会议中心举办,大会以”平台之上,应用无限”为主题,全景展现移动应用发展趋势.AppCan 移动技术蓝图及80万开发者的技术实践成果. 大会现场礼 ...

  6. hdu 3549 Flow Problem

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=3549 Flow Problem Description Network flow is a well- ...

  7. hdu 2112 HDU Today

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2112 HDU Today Description 经过锦囊相助,海东集团终于度过了危机,从此,HDU的 ...

  8. Android 解决图片大量下载:软引用必须懂4点

    1.对象的强.软.弱和虚引用为了能更加灵活控制对象的生命周期,需要知道对象引用的4中级别,由高到低依次为 :强引用.软引用.弱引用和虚引用 备注: 这四种的区别: ⑴强引用(StrongReferen ...

  9. JVM规范小结

    JVM规范组成: 1. 字节码(ByteCode): 以Class或Interface为基本单位, 具有固定结构. 2. 指令集(InstructionSet): 每个指令用一个字节表示, 最多256 ...

  10. [转]insmod

    [转]insmod http://www.cnblogs.com/amaoxiaozhu/archive/2013/03/08/2950002.html 在Linux下,驱动程序是内核的一部分,运行在 ...