Problem 67 Fibonacci sequence

Back to General discussions forum

Paul_Last     2015-04-16 18:44:03

Hi all, I believe I have worked out an algorithm which would solve this. However, problem seems to be that the numbers to be checked are just too big to work in java, even using the "long" type. Is there anything I am missing here? Any little hint to get me on right track would be appreciated :-)

Quandray     2015-04-16 19:30:14
User avatar

Hello Ireland. Greetings from Wales.

Think about how you'd do it with pen and paper...

AntonG     2015-05-11 15:24:37

I've got the same trouble. And this hint about pen and paper doesn't help at all. The main problem: how to enter these immense numbers to the program.

Quandray     2015-05-12 07:28:10
User avatar

There are multiple ways of solving this problem. This is one way.

If you have two enormous numbers, each containing many thousands of digits, one way of adding them is to do one digit at a time, e.g. say the numbers end with "...9483" and "...6271"

If you add 3+1=4 you know that the last digit of the answer is 4.
If you then add 8+7=15 you know that the last but one digit of the answer is 5 and there's 1 to carry.
Then, by adding 4+2+1=7 (the 1 is the carry) you know that the next digit of the answer is 7 (and nothing to carry). You now know that the answer ends with the digits "754".

If you continue until you reach the start of the two enormous numbers you'll have added them together.

Christopher Matthews     2015-05-13 09:11:41

Try reading up on modular arithmetic.

http://www.codeabbey.com/index/wiki/modular-arithmetic

That's the method I used to solve the problem.

-- Christopher P. Matthews

Please login and solve 5 problems to be able to post at forum