Java大数统计

Wesley13
• 阅读 371

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1316

题目描述:
Java大数统计Java大数统计

         给你一个范围,问你在这个范围内有多少斐波拉契数。

代码实现:

 1 import java.util.Scanner;
 2 import java.math.BigInteger;
 3 public class Main{
 4 
 5     @SuppressWarnings("null")
 6     public static void main(String[] args) {
 7         Scanner cin=new Scanner(System.in);
 8         int sum=0;
 9         BigInteger []big=new BigInteger[1005];//定义一个BigInteger类型的数组
10         big[1]=BigInteger.valueOf(1);
11         big[2]=BigInteger.valueOf(2);
12         //先将前1005个斐波拉契数求出来放在big数组里面
13         for(int i=3;i<1005;i++){
14             big[i]=big[i-1].add(big[i-2]);//大数相加,第i个数=第i-1个数+第i-2个数
15         }
16         while(cin.hasNext())
17         {
18             BigInteger a = cin.nextBigInteger();
19             BigInteger b = cin.nextBigInteger();
20             //如果a=0&&b=0,输入结束
21             if(a.compareTo(BigInteger.valueOf(0))==0&&b.compareTo(BigInteger.valueOf(0))==0) return;
22             for(int i=1;i<1005;i++){
23                 //如果big[i]这个数处在[a,b]范围内,sum+1
24                 if(big[i].compareTo(a)>=0&&big[i].compareTo(b)<=0){
25                     sum++;
26                 }
27             }
28             System.out.println(sum);
29             sum=0;
30         }
31         cin.close();
32     }
33 }
点赞
收藏
评论区
推荐文章
Wesley13 Wesley13
2年前
hdu2204 Eddy's爱好
原题:点击打开链接(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Facm.hdu.edu.cn%2Fshowproblem.php%3Fpid%3D2204)题意很明确了,即:给你一个正整数N,确定在1到N之间有多少个可以表示成M^K(K1)的数。本题目为容斥原
Stella981 Stella981
2年前
2019 HDOJ Multi
服务器时不时爆炸,有点难受。题目链接:http://acm.hdu.edu.cn/userloginex.php?cid849(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Facm.hdu.edu.cn%2Fuserloginex.php%3Fcid%3D849)
Wesley13 Wesley13
2年前
P2P技术揭秘.P2P网络技术原理与典型系统开发
Modular.Java(2009.06)\.Craig.Walls.文字版.pdf:http://www.t00y.com/file/59501950(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Fwww.t00y.com%2Ffile%2F59501950)\More.E
Stella981 Stella981
2年前
Codeforces Round #479 (Div. 3) F. Consecutive Subsequence
标签:DP题目链接(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Fcodeforces.com%2Fcontest%2F977%2Fproblem%2FF)
Wesley13 Wesley13
2年前
1418:猴子选大王
题目连接(本题目链接失效内容同《围圈报数》):http://ybt.ssoier.cn:8088/problem\_show.php?pid1418(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Fybt.ssoier.cn%3A8088%2Fproblem_show.php%3Fpid
可莉 可莉
2年前
2019 HDOJ Multi
服务器时不时爆炸,有点难受。题目链接:http://acm.hdu.edu.cn/userloginex.php?cid849(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Facm.hdu.edu.cn%2Fuserloginex.php%3Fcid%3D849)
Stella981 Stella981
2年前
HDU1005 Number Sequence
HDU1005NumberSequence(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Facm.hdu.edu.cn%2Fshowproblem.php%3Fpid%3D1005)对于公式f\n\A\f\n1\B\f\n2\,因为对于f\n1\
Stella981 Stella981
2年前
POJ 1195 Mobile phones(二维树状数组)
题目链接:http://poj.org/problem?id1195(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Fpoj.org%2Fproblem%3Fid%3D1195)题意是有四种操作。当n0时:输入一个m表示初始化矩阵(m\m且值都为0)。
Stella981 Stella981
2年前
Hdu
Sequence(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Facm.hdu.edu.cn%2Fshowproblem.php%3Fpid%3D6395)
Wesley13 Wesley13
2年前
BZOJ3168. [HEOI2013]钙铁锌硒维生素(线性代数+二分图匹配)
题目链接https://www.lydsy.com/JudgeOnline/problem.php?id3168(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fwww.lydsy.com%2FJudgeOnline%2Fproblem.php%3Fid%3D3168)题解