File: ifact.c

package info (click to toggle)
nickle 2.70-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 2,324 kB
  • ctags: 3,324
  • sloc: ansic: 31,410; yacc: 1,864; sh: 954; lex: 858; makefile: 238
file content (30 lines) | stat: -rw-r--r-- 524 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <stdio.h>
#include <gmp.h>

void ifact(mpz_t res, mpz_t n) {
  mpz_t count;
  mpz_init_set(count, n);
  mpz_set_si(res, 1);
  while(mpz_cmp_si(count, 2) >= 0) {
    mpz_mul(res, res, count);
    mpz_sub_ui(count, count, 1);
  }
  mpz_clear(count);
}

void do_ifact(signed long int xa) {
    mpz_t a, res;

    mpz_init_set_si(a, xa);
    mpz_init(res);
    ifact(res, a);
    mpz_clear(a);
    mpz_out_str(stdout, 10, res);
    putchar('\n');
    mpz_clear(res);
}

int main(void) {
  do_ifact(20000);
  exit(0);
}