top of page

Problem 16

This is a C++ solution to Project Euler problem 16 found at: https://projecteuler.net/problem=16

My Algorithm

For this problem, we are asked to find the sum of the digits of the number 2^1000. To do this, we can store 2^1000 in a double format since it is capable of holding a number this large since it is a power of 2. Next, we can loop through the entire large number and convert each digit to a character. After doing this, we can check if the character is zero or non-numeric. If this is the case, we can discard this digit since it is not useful (the non-numeric catches the decimal resulting from storing it as double). Finally, we can reconvert the digit into an integer and add it to a running sum, which we can return to get the final answer of 1366.

Full Solution on GitHub

© 2023 by Matthew Woodring

    bottom of page