Data Structures & AlgorithmsHardCodeforces Div2 B · big integers

Problem: What is the digit sum of 2^100? Run the code.

Problem: What is the digit sum of 2^100? Run the code.
print(sum(int(c) for c in str(2 ** 100)))
What is printed?
  1. A. 100
  2. B. 115
  3. C. 128
  4. D. 109

Correct answer: B. 115

Python integers are exact, so the decimal expansion of 2^100 gives a digit sum of 115. Estimating with 100 * log10(2) digits gives the digit count, not the sum.

More Coding Interview Problems questions

Exams that ask this topic