Fast Power Mod

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

2 10 1000
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

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
Output

                                        
Please login to submit solutions.