4

I'm solving problems in Project Euler. Most of the problems solved by

  1. big numbers that exceeds ulong,
Ex : ulong number = 81237146123746237846293567465365862854736263874623654728568263582;
  1. very sensitive decimal numbers with significant digits over 30

Ex : decimal dec = 0,3242342543573894756936576474978265726385428569234753964340653;

  1. arrays that must have index values that exceeds biggest int value.

Ex : bool[] items = new bool[213192471235494658346583465340673475263842864836];

I found a library called IntX to solve this big numbers. But I wonder how can I solve this problems with basic .NET types ?

Thanks for the replies !

5 Answers 5

8

Well, for the third item there you really don't want to use an array, since it needs to be allocated that big as well.

Let me rephrase that.

By the time you can afford, and get access to, that much memory, the big-number problem will be solved!

To answer your last question there, there is no way you can solve this using only basic types, unless you do what the makers of IntX did, implement big-number support.

Might I suggest you try a different programming language for the euler-problems? I've had better luck with Python, since it has support for big numbers out of the box and integrated into everything else. Well, except for that array, you really can't do that in any language these days.

1
  • Java has BigInteger and BigDecimal too
    – Malfist
    Feb 21, 2009 at 20:47
4

Maybe this could give you ideas to how to solve part of your problem: http://www.codeproject.com/csharp/BigInteger.asp

Wikipedia also has a good article about Arbitrary-precision math and in that article there is a link to Codeplex and W3b.sine wich is an arbitrary precision real number c# library.

2

Well, I suggest you take look at this other answer to see how I solved the Big Numbers problem. Basically, you need to represent numbers in another way ...

0
1

Most of the problems solved by

  1. big numbers that exceeds ulong,
  2. very sensitive decimal numbers with significant digits over 30
  3. arrays that must have index values that exceeds biggest int value.

Most of the problems are designed to fit within 64 bit longs. There are one or two which require bigger integers, but not many. None I've seen require decimal numbers with more than 30 digits, and none require arrays larger than a few thousand entries.

Remember that the correct solutions to the problems should run in a few seconds at most, and populating an array of 213192471235494658346583465340673475263842864836 bits will take 10^30 years.

0

Another options might be to use the BigInt type that is available in F#: http://cs.hubfs.net/forums/thread/887.aspx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.