- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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
Advertisements