Data Structures & AlgorithmsVery hardProduct Company SDE · CP practice
Problem: How many integers from 1 to 1000 are not divisible by any of 2, 3, 5 and 7? Run the code.
Problem: How many integers from 1 to 1000 are not divisible by any of 2, 3, 5 and 7? Run the code.
print(sum(1 for x in range(1, 1001) if x % 2 and x % 3 and x % 5 and x % 7))What is printed?
- A. 229
- B. 228
- C. 266
- D. 772
Correct answer: B. 228
48 of every 210 numbers are coprime to 210; direct counting up to 1000 gives 228. Rounding 1000 · 48/210 up gives 229, ignoring 7 gives 266, and 772 is the complement.
More Coding Interview Problems questions
- Problem: What is the maximum sum of a subsequence (not necessarily contiguous) of [4, -2, 5, -1, 3] with no two chosen elements adjacent?…
- Problem: How many ways are there to write 12 as a sum of distinct positive integers (partitions into distinct parts)? Run the DP. python…
- Problem: What is the number of trailing zeros of 25 40 125? Run the code. python n = 25 40 125 c = 0 while n % 10 == 0: n //= 10 c += 1…
- Problem: How many integer pairs (x, y) with 1 <= x <= 10 and 1 <= y <= 10 satisfy x y being a perfect cube? Run the code. python…
- Problem: What is the longest run of consecutive integers that all have at least one divisor in common with 30 (gcd greater than 1)…
- Problem: How many integers in [1, 500] are divisible by 4 or by 6 but not by 12? Run the code. python print(sum(1 for x in range(1, 501)…