Suppose we are given two integer numbers p and q. We have to find out the value of 22^p mod q. The output has to be an integer.
So, if the input is like p = 5, q = 6, then the output will be 4
To solve this, we will follow these steps −
- res := 2^(2^p) mod q
- return res
Example
Let us see the following implementation to get better understanding −
def solve(p, q): res = pow(2, 2 ** p, q) return res print(solve(5, 6))
Input
5, 6
Output
4