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?
- A. 100
- B. 115
- C. 128
- 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
- Problem: How many triples (a, b, c) with 1 <= a <= b <= c <= 10 have a + b + c = 12? Run the code. python print(sum(1 for a in range(1…
- Problem: What is the largest prime factor of 600851475143? Run the trial-division code. python n = 600851475143 f = 2 last = 1 while f f…
- Problem: How many integers in [1, 999] are divisible by 7 but not by 14? Run the code. python print(sum(1 for x in range(1, 1000) if x % 7…
- Problem: How many ordered pairs (i < j) of [1, 2, 3, 4, 6] have a[j] divisible by a[i]? Run the code. python a = [1, 2, 3, 4, 6]…
- Problem: What is the minimum number of operations to go from 1 to 10 when each operation is +1 or 2? Run the BFS. python from collections…
- Problem: How many binary strings of length 4 avoid the substring '11'? Run the code. python print(sum(1 for t in range(16) if '11' not in…