Another solution using Bignum support.
This commit is contained in:
parent
a7fb4daffc
commit
6c26f6f8f4
1 changed files with 26 additions and 0 deletions
26
16/euler16.cpp
Normal file
26
16/euler16.cpp
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
// This solution needs the GNU MP Bignum library
|
||||||
|
// g++ euler16.cpp -o euler16 -lgmpxx -lgmp
|
||||||
|
|
||||||
|
#include <gmpxx.h>
|
||||||
|
#include <cmath>
|
||||||
|
#include <vector>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
mpz_class power = 1;
|
||||||
|
mpz_class modulo = 0;
|
||||||
|
mpz_class tens = 10;
|
||||||
|
mpz_class digitsum = 0;
|
||||||
|
|
||||||
|
for (int i = 1; i <= 1000; ++i) {
|
||||||
|
power *= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (power != 0) {
|
||||||
|
digitsum = digitsum + power % tens;
|
||||||
|
power = power / 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << digitsum << std::endl;
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
Reference in a new issue