Find the value of P and modular inverse of Q modulo 998244353 | C ++ implementation to find the value of P . Q - 1 mod 998244353 ; Function to find the value of P * Q ^ - 1 mod 998244353 ; Loop to find the value until the expo is not zero ; Multiply p with q if expo is odd ; Reduce the value of expo by 2 ; Driver code ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; long long calculate ( long long p , long long q ) { long long mod = 998244353 , expo ; expo = mod - 2 ; while ( expo ) { if ( expo & 1 ) { p = ( p * q ) % mod ; } q = ( q * q ) % mod ; expo >>= 1 ; } return p ; } int main ( ) { int p = 1 , q = 4 ; cout << calculate ( p , q ) << ' ' ; return 0 ; }