Skip to content

Instantly share code, notes, and snippets.

@ljmccarthy
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ljmccarthy/6e5c7943d04f156038e3 to your computer and use it in GitHub Desktop.
Save ljmccarthy/6e5c7943d04f156038e3 to your computer and use it in GitHub Desktop.
Compute factorial(1000) with libtommath
#include <stdio.h>
#include "tommath.h"
int main()
{
mp_int a, b, c;
mp_init(&a);
mp_init(&b);
mp_init(&c);
mp_set_int(&a, 1);
int n = 0;
while (n <= 1000) {
//char buf[4096];
//mp_toradix_n(&a, buf, 10, sizeof(buf)-1);
//printf("fac(%d) = %s\n", n, buf);
mp_set_int(&b, ++n);
mp_mul(&a, &b, &c);
mp_copy(&c, &a);
}
mp_clear(&a);
mp_clear(&b);
mp_clear(&c);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment