K45
Fast Exponentiation (Pow x, n)
Problem Statement & Objective
Implement pow(x, n), which calculates x raised to the power n in O(log n) time using binary exponentiation.
Function Signature (Python)
pow_mod(base: int, exp: int, mod: int) -> intInput & Output Contract
Output Rule:Modüler üs alma sonucu tam sayısı.
System Constraints
1 <= taban, mod <= 10^9
0 <= us <= 10^9Example Execution Walkthrough
taban = 2, us = 10, mod = 1000 -> 2^10 = 1024 -> 1024 % 1000 = 24Example Test Scenarios (3)
Example 1
Input:
[2,10,1000]Expected Output:
24Example 2: 0. Kuvvet
Input:
[3,0,7]Expected Output:
1Example 3: 125 % 13 = 8
Input:
[5,3,13]Expected Output:
8