• Post Reply Bookmark Topic Watch Topic
  • New Topic

Question regarding Big Integer  RSS feed

 
dhrubo bhattacharjee
Greenhorn
Posts: 23
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't believe there is an upper limit to BigInteger.

That's not what you asked, huh? Try using compareTo()
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!