Sign in $ create-account
~/problems ~/discussion ~/contests ~/submission
← ~/problems
P2009

Modular Exponentiation

Medium
// Description
Given a, b and m, compute a raised to the power b, modulo m.
// Input
A single line with three integers a, b and m (0 <= a, b <= 10^9, 1 <= m <= 10^9).
// Output
The value of a^b mod m.
// Hint
Use fast (binary) exponentiation in O(log b).
// Samples
Sample Input
2 10 1000
Sample Output
24
// Problem Info
DifficultyMedium
Acceptance70%
Time Limit1000 ms
Memory Limit65536 KB
Accepted7