Given two integer P and Q, the task is to find the value of P and modular inverse of Q modulo 998244353. That is
Note: P and Q are co-prime integers
Input: P = 1, Q = 4
Refer below for the explanation of the example.
Input: P = 1, Q = 16
Approach: The key observation in the problem is that Q is co-prime with the 998244353, Then Q-1 always exists which can be computed using Extended euclidean Algorithm
For P = 1 and Q = 4
We know that,
That is, 4 * 748683265 = 2994733060 equivalent to 1 mod 998244353
Therefore, 1*4^(-1) = 748683265
Below is the implementation of the above approach:
- Modular Exponentiation (Power in Modular Arithmetic)
- Modular multiplicative inverse from 1 to n
- Modular multiplicative inverse
- Count array elements having modular inverse under given prime number P equal to itself
- XOR of array elements whose modular inverse with a given number exists
- Chinese Remainder Theorem | Set 2 (Inverse Modulo based Implementation)
- Nearest smaller number to N having multiplicative inverse under modulo N equal to that number
- Find modular node in a linked list
- Find the largest possible value of K such that K modulo X is Y
- Find sum of inverse of the divisors when sum of divisors and the number is given
- How to avoid overflow in modular multiplication?
- Modular Division
- Using Chinese Remainder Theorem to Combine Modular equations
- Number of solutions to Modular Equations
- Modular exponentiation (Recursive)
- Modular Exponentiation of Complex Numbers
- Modular Multiplication
- Modular Addition
- Modular Arithmetic
- Trick for modular division ( (x1 * x2 .... xn) / b ) mod (m)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.