-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHowManyFibs.java
More file actions
53 lines (41 loc) · 1.19 KB
/
HowManyFibs.java
File metadata and controls
53 lines (41 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import java.math.BigInteger;
import java.util.LinkedList;
import java.util.Scanner;
public class HowManyFibs {
static LinkedList<BigInteger> longs = new LinkedList<>();
static void Fibon(BigInteger n1, BigInteger n2,BigInteger b) {
while (true) {
BigInteger c = n1.add(n2);
n1 = n2;
n2 = c;
if (c.compareTo(b) <=0) {
longs.add(c);
} else {
break;
}
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
BigInteger a,b;
BigInteger n1 = new BigInteger("0");
BigInteger n2 = new BigInteger("1");
while(sc.hasNext()){
a = sc.nextBigInteger();
b = sc.nextBigInteger();
if(a.compareTo(new BigInteger("0")) == 0 && b.compareTo(new BigInteger("0")) == 0)
break;
Fibon(n1, n2,b);
int count = 0;
for (BigInteger aLong : longs) {
if (aLong.compareTo(a) >= 0)
{
count++;
}
}
System.out.println(count);
longs.clear();
count = 0;
}
}
}