posted 2 years ago

I was working on the following problem that was a modification of the Project Euler Problem 2:

I was able to solve the Project Euler problem currectly but however I am stuck on this one as I cannot understand how do I check the constarint no. 2.

Here is my code so far :

Can Someone please tell me how do I check if the range is greater than 4×10^16 using Big Integer?

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1,2,3,5,8,13,21,34,55,89,⋯

By considering the terms in the Fibonacci sequence whose values do not exceed N, find the sum of the even-valued terms.

Input Format

First line contains T that denotes the number of test cases. This is followed by T lines, each containing an integer, N.

Output Format

Print the required answer for each test case.

Constraints

1.1≤T≤105

2.10≤N≤4×10^16

I was able to solve the Project Euler problem currectly but however I am stuck on this one as I cannot understand how do I check the constarint no. 2.

Here is my code so far :

Can Someone please tell me how do I check if the range is greater than 4×10^16 using Big Integer?

posted 2 years ago
~~I don't believe there is an upper limit to BigInteger.~~

That's not what you asked, huh? Try using compareTo()

That's not what you asked, huh? Try using compareTo()

All things are lawful, but not all things are profitable.