Data Structures & AlgorithmsHardProduct Company SDE · CP practice
Problem: How many integers x in [1, 2000] satisfy x^2 ≡ x (mod 10)? Run the code.
Problem: How many integers x in [1, 2000] satisfy x^2 ≡ x (mod 10)? Run the code.
print(sum(1 for x in range(1, 2001) if (x * x - x) % 10 == 0))What is printed?
- A. 400
- B. 600
- C. 800
- D. 80
Correct answer: C. 800
x(x − 1) is always even, so it needs 5 | x(x − 1), i.e. x mod 10 ∈ {0, 1, 5, 6}: 4/10 of 2000 = 800. Only 0 and 1 gives 400, missing one of 5 or 6 gives 600, and requiring x² ≡ x (mod 100) gives 80.
More Coding Interview Problems questions
- Problem: How many inversions does the array [2, 3, 8, 6, 1] have? Run the code. python a = [2, 3, 8, 6, 1] print(sum(1 for i in…
- Problem: What is the number of distinct subarray sums of [1, 2, 3] (non-empty subarrays)? Run the code. python a = [1, 2, 3]…
- Problem: What is the sum of all two-digit numbers that are divisible by the sum of their digits? Run the code. python print(sum(x for x in…
- Problem: How many integers in [1, 1000] are both perfect squares and perfect cubes? Run the code. python print(sum(1 for x in range(1…
- Problem: How many integers in [1, 100] are divisible by neither 2 nor 3? Run the code. python print(sum(1 for x in range(1, 101) if x % 2…
- Problem: How many ordered pairs (a, b) with 1 <= a, b <= 9 make a b a perfect square? Run the code. python print(sum(1 for a in range(1…