aboutsummaryrefslogtreecommitdiffstats
path: root/16-Power-Digit-Sum
diff options
context:
space:
mode:
Diffstat (limited to '16-Power-Digit-Sum')
-rwxr-xr-x16-Power-Digit-Sum/sumexpbin0 -> 16800 bytes
-rw-r--r--16-Power-Digit-Sum/sumexp.c24
2 files changed, 24 insertions, 0 deletions
diff --git a/16-Power-Digit-Sum/sumexp b/16-Power-Digit-Sum/sumexp
new file mode 100755
index 0000000..854ac69
--- /dev/null
+++ b/16-Power-Digit-Sum/sumexp
Binary files differ
diff --git a/16-Power-Digit-Sum/sumexp.c b/16-Power-Digit-Sum/sumexp.c
new file mode 100644
index 0000000..7d471ab
--- /dev/null
+++ b/16-Power-Digit-Sum/sumexp.c
@@ -0,0 +1,24 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <gmp.h>
+
+// Compile Notes: use `gcc <program>.c -lgmp`
+
+
+int main(){
+ mpz_t num, remainder;
+ unsigned long sum = 0;
+ mpz_init(num);
+ mpz_init(remainder);
+ // From docs, this assigns the value num to the value 2^1000
+ mpz_ui_pow_ui(num, 2, 1000);
+
+ // mpz_sgn returns 1 if positive, 0 if 0, -1 if negative
+ while(mpz_sgn(num)){
+ sum += mpz_mod_ui(remainder, num, 10);
+ mpz_fdiv_q_ui(num, num, 10);
+ }
+ printf("%lu\n", sum);
+ return 0;
+}
+