Data Structures & AlgorithmsModerateCodeforces Div2 B · modular arithmetic
Problem: How many integers x in [1, 100] satisfy x^2 ≡ 1 (mod 8)? Run the code.
Problem: How many integers x in [1, 100] satisfy x^2 ≡ 1 (mod 8)? Run the code.
print(sum(1 for x in range(1, 101) if (x * x) % 8 == 1))What is printed?
- A. 50
- B. 25
- C. 75
- D. 100
Correct answer: A. 50
x^2 ≡ 1 (mod 8) holds exactly for odd x, and there are 50 odd numbers in [1, 100].
More Coding Interview Problems questions
- Problem: What is the smallest positive integer x with x ≡ 1 (mod 4) and x ≡ 2 (mod 5)? Run the code. python print(next(x for x in range(1…
- Problem: How many integers in [1, 100] have non-decreasing decimal digits (for example 1245 or 3399, but 2 digits only here)? Run the…
- Problem: What is the spiral (clockwise from the top-left) traversal of the matrix [[1,2,3],[4,5,6],[7,8,9]]? Print the list produced by…
- Problem: How many swaps does insertion sort perform on [3, 2, 1]? Count the shifts in the code. python a = [3, 2, 1] swaps = 0 for i in…
- Problem: What is the minimum number of intervals from [[1,4],[3,7],[6,10],[9,10]] needed to cover the segment [1, 10]? Run the greedy…
- Problem: How many pairs (i < j) of [1, 2, 3, 4, 5] have a[i] XOR a[j] = 1? Run the code. python a = [1, 2, 3, 4, 5] print(sum(1 for i in…