Data Structures & AlgorithmsModerateProduct Company SDE · CP practice
Problem: What is the sum of all distinct prime factors of 2025? Run the code.
Problem: What is the sum of all distinct prime factors of 2025? Run the code.
n = 2025
f = 2
ps = set()
while f * f <= n:
while n % f == 0:
ps.add(f)
n //= f
f += 1
if n > 1:
ps.add(n)
print(sum(ps))What is printed?- A. 22
- B. 15
- C. 6
- D. 8
Correct answer: D. 8
2025 = 3⁴ · 5², so the distinct primes are 3 and 5, sum 8. Adding each prime with multiplicity gives 22, multiplying them gives 15, and adding the exponents gives 6.
More Coding Interview Problems questions
- Problem: How many integers x in [1, 500] have x^2 + x + 41 prime? Run the code. python def isp(n): return n > 1 and all(n % d for d in…
- Problem: What is the length of the longest subarray of [2, 4, 6, 3, 8, 10, 12] whose elements are all even? Run the code. python a = [2…
- Problem: How many distinct values does floor(100 / i) take for i = 1 to 100? Run the code. python print(len({100 // i for i in range(1…
- Problem: What is the number of ways to write 20 as an ordered sum of the parts 1 and 2 (compositions)? Run the DP. python f = [1, 1] for i…
- Problem: How many 4-digit numbers have all digits equal to or greater than the digit before them (non-decreasing)? Run the code. python…
- Problem: What is the maximum value of a[i] XOR a[j] over i < j for a = [3, 10, 5, 25, 2, 8, 17]? Run the code. python a = [3, 10, 5, 25…