programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Jeanne Boyarsky
• Ron McLeod
• Paul Clapham
• Liutauras Vilda
Sheriffs:
• paul wheaton
• Rob Spoor
• Devaka Cooray
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Carey Brown
• Frits Walraven
• Tim Moores
Bartenders:
• Mikalai Zaikin

# Question regarding Big Integer

Greenhorn
Posts: 27
• Number of slices to send:
Optional 'thank-you' note:
I was working on the following problem that was a modification of the Project Euler Problem 2:

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?

Sheriff
Posts: 7125
184
• Number of slices to send:
Optional 'thank-you' note:
I don't believe there is an upper limit to BigInteger.

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

 Don't get me started about those stupid light bulbs.