All pastes #935536 Raw Edit

Divisors

public c v1 · immutable
·published 2008-03-09 18:40 UTC
rendered paste body
#include <stdio.h>#include <string.h>#include <gmp.h>int main(void) {	mpz_t d, n, lim; 	char str[1000];	char tmp[100];		mpz_init (d);    mpz_init_set_str (d, "2", 0);		mpz_init (n);	printf("Enter an integer: ");	gmp_scanf("%Zd", n);			mpz_init(lim);	mpz_sqrt(lim,n);		while (mpz_cmp(lim,d)>=0) {		if (mpz_divisible_p(n,d)) {			gmp_sprintf(tmp,"%Zd*",d);			strcat(str,tmp);			mpz_divexact(n,n,d);			mpz_sqrt(lim,n);			continue;		}		mpz_add_ui (d, d, mpz_cmp_ui(d,2)>0?2:1);		if (mpz_divisible_ui_p(d,10001)) {			printf("+");		}	}		if (mpz_cmp_ui(n,1)>0) {		gmp_sprintf(tmp,"%Zd",n);		strcat(str,tmp);	}		printf("\nDivisors: %s",str);	return 0;}