Data Structures & AlgorithmsHardCodeforces Div2 B · modular inverse
Problem: What does the following print? It is the multiplicative inverse of 7 modulo 26.
Problem: What does the following print? It is the multiplicative inverse of 7 modulo 26.
print(pow(7, -1, 26))
- A. 15
- B. 11
- C. 19
- D. 23
Correct answer: A. 15
7 * 15 = 105 = 4 * 26 + 1, so 15 is the inverse. The inverse exists only because gcd(7, 26) = 1, and 11 is the trap that results from a sign slip.
More Coding Interview Problems questions
- Problem: How many trailing zeros does 100! have? Run the code that counts factors of 5. python n = 100 c = 0 p = 5 while p <= n: c += n //…
- Problem: Starting from 27, the Collatz map is n -> n/2 if n is even and n -> 3n+1 if n is odd. How many steps does it take to first reach…
- Problem: Find the smallest positive integer n such that n! has at least 6 trailing zeros. Run the code. python def zeros(n): c = 0 p = 5…
- Problem: Find the length of the longest strictly increasing subsequence of [10, 9, 2, 5, 3, 7, 101, 18] with the O(n log n) tails method…
- Problem: Coins of values 2, 5, 10 and 1 are available with unlimited copies. What is the minimum number of coins summing to 27? Run the…
- Problem: How many ways are there to make change for 100 using coins of 1, 5, 10, 25 and 50 (order does not matter)? Run the code. python…