Saturday, March 12, 2011

[ohnnujur] Factorial with GNU MP

#include <gmp.h>
#include <cstdlib>
#include <iostream>

//g++ -o x.gmp-factorial -I /mit/gp/gmp/arch/amd64_ubuntu1004/include gmp-factorial.cpp /mit/gp/gmp/arch/amd64_ubuntu1004/lib/libgmp.a

int main(int argc,char**argv){
  unsigned long int small=atoll(argv[1]);
  std::cout << small <<"! = ";
  mpz_t x;
  mpz_init(x);
  mpz_fac_ui(x,small);
  std::cout <<  mpz_sizeinbase(x,2) << " bits" << std::endl;
}

ulimit -v 8388608
458994783! = 12544881660 bits
470012140! = 12862083270 bits
18 minutes
gmp-5.0.1

(11!)! = 950331113 bits on a smaller computer, 2 minutes 45 seconds. (vs 0 minutes 50 seconds on the same computer as above).

(12!)! = 479001600! is slightly out of reach with computers I easily have access to.

No comments :