Skip to content

Instantly share code, notes, and snippets.

@vmxdev
Last active February 3, 2021 05:48
Show Gist options
  • Save vmxdev/d89f7420bc04c0c904fd747b097335d5 to your computer and use it in GitHub Desktop.
Save vmxdev/d89f7420bc04c0c904fd747b097335d5 to your computer and use it in GitHub Desktop.
Calculate factorials using gmp
/*
* $ cc -O3 -Wall -pedantic -Wextra fact.c -lgmp
*/
#include <stdio.h>
#include <gmp.h>
static void
factorial(long n, mpz_t r)
{
mpz_init_set_si(r, 1);
for (; n > 1; n--) {
mpz_mul_si(r, r, n);
}
}
int
main (void)
{
int i;
mpz_t r;
for (i=0; i<14888; i++) {
factorial(i, r);
gmp_printf ("%Zd\n", r);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment