05-13-2009 08:51 AM
Today I had nothing to do, so I participated in Project Euler http://projecteuler.net with Labview. I'm at question 10 now. The question itself isn't much of a challenge, but the problem I'm having is that the datatypes are to small for the value I would like to put in there. The value first goes up, then changes from + to - and then goes back to zero. This all happens while I'm just adding up to the value.
I guess there is a sollution to this problem but I don't seem to find it. Is there someone who can and will help me please?
05-13-2009 10:32 PM
05-14-2009 04:31 AM
For example:
Calculate the full value of 2^1000. Even if I use the 64bit datatype I come in (very) short.
Thank you very much for your response!
05-14-2009 06:07 AM
by the way, I am using integers because the result has to be accurate. In the end I need the sum of all numbers of the result.
(example: 456789 becomes 4+5+6+7+8+9 = 39 and the 39 is what I need)
05-14-2009 12:33 PM
Well, the link you gave said problem 10 was "Find the sum of all the primes below two million", a little different problem than 2^1000.
In order represent 2^1000 at full resolution, you would need a 1000 bit number! Of course a U64 won't be able to hold it. A double will hold it and it comes to about 1.07...e301, so 301 decimal digits. But a double won't store the full resolution.
In order to do what you want, you will have to set up your own math functions using 125+ bytes. You will have to do the multiplication and do all of your own carries. That why they made it a problem, to challenge you to figure out the algorhitm to do it. Otherwise going 2^1000 in any programming language is a trivial exercise.