Source

snippets / euler / 016.c

Full commit
#include <ctype.h>
#include <gmp.h>
#include <stdio.h>

int numdigits(mpz_t n) {
	return 2;
}

int main() {
	mpz_t a;
	size_t len;
	char *strp, *ip;
	int acc;

	mpz_init(a);

	mpz_set_ui(a, 2);
	mpz_pow_ui(a, a, 1000);

	gmp_asprintf(&strp, "%Zd", a);
	for(ip = strp, acc = 0; isdigit(*ip); ip++) {
		acc += *ip - '0';
	}
	printf("%i\n", acc);

	return 0;
}