- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Program to find out the value of a power of 2 in Python

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

- Related Questions & Answers
- Program to find Reordered Power of 2 in Python
- Program to Find Out the Maximum Final Power of a List in Python
- Program to find out the value of a given equation in Python
- Program to find sum of the 2 power sum of all subarray sums of a given array in Python
- Find value of y mod (2 raised to power x) in C++
- Python Program to find out the number of sets greater than a given value
- C++ program to find out the maximum value of i
- Program to find out the maximum value of a 'valid' array in Python
- C/C++ Program to Find sum of Series with n-th term as n power of 2 - (n-1) power of 2
- Python Program to find whether a no is the power of two
- Program to find out the largest sum value of a BST in a given binary tree in Python
- Program to find out the minimum value from sum of node values of sub-trees in Python
- Golang Program to round up the next highest power of 2.
- Golang Program to round up the next previous power of 2.
- Python Program to find out the determinant of a given special matrix

Advertisements