Best bignum library to solve Project Euler problems in C++? [closed]
Asked Answered
C

3

18

I am still a student, and I find project Euler very fun.

sometimes the question requires calculations that are bigger than primitive types. I know you can implement it but I am too lazy to do this,

So I tried few libraries,

MAPM :: very good performance, but it provides only big floats, with the possibility to check if it is an integer. very good to accept input, but nasty to provide output, and compiles like magic with Visual C++ 2008 express.

bigint :: a small one, but needs a re engineering in many parts. Very simple to use, but very limited power, and very slow compared to others. only big integers.

ttmath :: the most beautiful one I have tried until now!, just some files to include and you have unbelievable power/simplicity. Compiles like magic in Visual C++ 2008 express. It is fast, because it provides fixed-length numbers. It is built using Metaprogramming in C++. The only disadvantage I see, is that numbers are not arbitrary in length at run-time, but you can have 1024K numbers when writing code very easily,

ttmath::UInt<1024 * 1024> reallyHugeUnsignedInteger;

It provides three types: signed, unsigned and float.

I tried to compile gmp under VC2008 express, but I failed! I know it is the best, but no where easy to compile for a beginner under VC2008 express, I appreciate also if you point to a tutorial to compile gmp under VC.

EDIT :: If you know how to compile gmp using VC 2008, Please explain to me and get the bounty :)

EITD :: It seems that I was not using the right terms, So here is the magical GMP for Windows! works with VC 2008 :) MPIR

Carolynecarolynn answered 26/6, 2009 at 3:39 Comment(4)
Note: You may need a bignum library to solve some problems, but most of the Euler problems don't really need it. When you need to find some property of a very large number, usually it's very inefficient to really calculate it to find the property. Often you need to analyze the problem and find a better solution. For example, if you need to find the number of zeros in 1000!, calculating the actual value of 1000! would be a very inefficient solution.Pokey
good point, but I don't always get the optimal solution :)Carolynecarolynn
@Igor: if the inefficient solution runs in under a second and takes a couple of minutes to write, I'm not interested in the efficient one. Yes, I've done some Euler questions, and yes there have been occasions where throwing GMP at the problem has solved it immediately. 1000! is less than 10 000 binary digits, it's probably fairly trivial to calculate on a PC. It's certainly faster than working out the number of trailing zeroes in 1000! by hand (although, granted, that's not so tricky either).Palmation
Good point Igor & Steve! Your comments complement each other very well.Wolsky
P
5

Here are a couple of links regarding GMP and Visual Studio 2008:

GMP Install Help at CodeGuru

GMP Compile Guide at The Edge Of Nowhere (this one looks really thorough)

Promethium answered 1/7, 2009 at 15:27 Comment(0)
G
4

... or just try out PARI/GP http://pari.math.u-bordeaux.fr/

Garish answered 2/7, 2009 at 5:35 Comment(0)
S
1

GMP. Simple API, been around forever.

Edit: Oh, you tried that. I'd really try it again, it is the best.

Stansberry answered 26/6, 2009 at 3:54 Comment(2)
As I said, I never got it to work under VC :(Carolynecarolynn
suggestion: for the benefit of other SO readers, next time please add links. I'm doing it for you now.Harsh

© 2022 - 2024 — McMap. All rights reserved.