MeetCode
Fast Power Mod
C
C++
Computer Mathematics
CSS
DSA
HTML
Java
JavaScript
NodeJS
PHP
Programming Interview
Python
ReactJS
SQL
Run
Submit
Dark
Problem Statement
Solutions
Submissions
Fast Power Mod
Medium
Computer Mathematics
Modular Arithmetic
28 views
Explanation
Complexity
Problem Statement
Compute a^b mod m.
Input Format
Three integers a b m.
Output Format
One integer.
Example
Input
2 10 1000
Output
24
Constraints
0
Input / Output Format
Input Format
Three integers a b m.
Output Format
One integer.
Constraints
0
Examples
Input:
2 10 1000
Output:
24
Example Solution (Public)
Computer Mathematics
Binary exponentiation: res=1; while b>0 if b odd res=res*a%m; a=a*a%m; b=floor(b/2).
Official Solution Code
Wrap
Copy
Binary exponentiation: res=1; while b>0 if b odd res=res*a%m; a=a*a%m; b=floor(b/2).
Please
login
to submit solutions.
Editor
C
C++
Computer Mathematics
CSS
DSA
HTML
Java
JavaScript
NodeJS
PHP
Programming Interview
Python
ReactJS
SQL
Test Cases
Output
Submission Result
Input
2 10 1000
Expected Output
24
Compile Output
Error
Output
Please
login
to submit solutions.