Data Structures & AlgorithmsModerateCodeforces Div2 B · modular arithmetic
Problem: What is 3^100 mod 10?
- A. 9
- B. 3
- C. 7
- D. 1
Correct answer: D. 1
The last digit of powers of 3 cycles 3, 9, 7, 1 with period 4. Since 100 is divisible by 4, the result is 1.
More Coding Interview Problems questions
- Problem: How many positive divisors does 2^4 3^2 5 7 have?
- Problem: Minimum insertions of brackets to make the string '(()))(' valid, found by this greedy scan? python s = '(()))(' bal = 0 ins = 0…
- Problem: How many contiguous subarrays of [1, 2, 1, 2, 1, 3, 1] contain exactly 2 odd numbers? python a = [1, 2, 1, 2, 1, 3, 1] k = 2 cnt…
- Problem: How many subsets of {1, 2, 3, 4, 5, 6, 7, 8} have a sum of exactly 10? python cnt = 0 for m in range(1 << 8): if sum(i + 1 for i…
- Problem: After running Floyd-Warshall on a directed graph with possibly negative edges, which check correctly detects that vertex i lies…
- Problem: A road graph has V = 10^5 vertices and E = 3 10^5 edges, all weights non-negative, and you need shortest paths from one source…