Back to Problem Solutions forum
Hey guys, I can't seem to solve problem number 67. I've written an array with the fibonacci-sequence with the first 1000 values and I want to compare the input against these values. With lower number it's possible without a problem, but as soon as the number gets too big I get a "Segmentation fault (core dumped)" error message from this site.
Any help is appreciated!
Are you sure that C can manage such huge numbers?
Yes, I'm afraid Nicolas is pretty correct - in C/C++
you are to implement "long arithmetic" storing
numbers in arrays and writing a function to sum them. However this should not be hard.
Why are the test-cases so long?
To teach working with long arithmetics in one manner or another :)
I see. Is using modular arithmetic the preferred method?
No, not neccessarily! I just propose exercises, but everyone can decide what approach to practice if there are more than one :)
In C, ULLONG_MAX <limits.h> is defined as +18,446,744,073,709,551,615. So, the answer would be to either implement your own big integer type, or use a third party library.
However, I personally would use modular arithmetic.
-- Christopher P. Matthews