This repository has been archived on 2024-01-26. You can view files and clone it, but cannot push or open issues or pull requests.
project-euler/e0016/euler0016.cpp

27 lines
527 B
C++
Raw Normal View History

2017-05-22 21:19:59 +02:00
// 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;
}