Data Structures & AlgorithmsHardProduct Company SDE · CP practice
Problem: How many integers in [1, 100] have exactly 3 divisors? Run the code.
Problem: How many integers in [1, 100] have exactly 3 divisors? Run the code.
print(sum(1 for x in range(1, 101) if sum(1 for d in range(1, x + 1) if x % d == 0) == 3))What is printed?
- A. 4
- B. 5
- C. 3
- D. 6
Correct answer: A. 4
Only squares of primes have exactly three divisors, and the primes up to 10 give 4, 9, 25 and 49.
More Coding Interview Problems questions
- Problem: What is the sum of the digits of 3^20? Run the code. python print(sum(int(c) for c in str(3 20))) What is printed?
- Problem: How many paths of length 3 exist in a complete graph K4 that start and end at different vertices? Run the code (count ordered…
- Problem: What is the number of integers in [1, 1000] whose digits are all odd? Run the code. python print(sum(1 for x in range(1, 1001) if…
- Problem: What is the length of the longest subarray of [5, 1, 4, 2, 3, 6] whose elements can be sorted to form consecutive integers? Run…
- Problem: How many integers from 1 to 1000 are not divisible by any of 2, 3, 5 and 7? Run the code. python print(sum(1 for x in range(1…
- Problem: What is the maximum sum of a subsequence (not necessarily contiguous) of [4, -2, 5, -1, 3] with no two chosen elements adjacent?…