
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python program for Modular Exponentiation
Given three numbers x, y and z, our task is to calculate (x^y) % z
Example
Input: x = 2, y = 3, p = 3 Output: 2
Explanation : 2^3 % 3= 8 % 3 = 2.
Algorithm
Step 1: Input three numbers. Step 2: then we use pow() to calculating power and % for modular. Step 3: display result.
Example Code
x = int(input("Enter First Value ::>")) y = int(input("Enter Second Value ::>")) z= (int)(1e9+7) # pow function use d = pow(x, y) % z print ("Value Is=",d)
Output
Enter First Value ::> 2 Enter Second Value ::> 3 Value Is= 8
- Related Articles
- C++ Program to Implement Modular Exponentiation Algorithm
- Modular Exponentiation (Power in Modular Arithmetic) in java
- C/C++ Program for Number of solutions to Modular Equations?
- Program for Number of solutions to Modular Equations in C/C++?
- C/C++ Program for Number of solutions to the Modular Equations?
- C++ Program to Find Fibonacci Numbers using Matrix Exponentiation
- Explain exponentiation operator in JavaScript?
- Explain modular automation framework.
- Modular multiplicative inverse in java
- Python Program for QuickSort
- Find Nth term (A matrix exponentiation example) in C++
- How Motorola made Modular Smartphone a Reality
- What is Modular Arithmetic in Information Security?
- Unit Testing Challenges with Modular JavaScript Patterns
- Python program for Complex Numbers

Advertisements