K45

Fast Exponentiation (Pow x, n)

Junior Level Candidate
Target Time: 15 - 20 Minutes
Type: NUMERIC

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) -> int

Input & Output Contract

Output Rule:Modüler üs alma sonucu tam sayısı.

System Constraints

1 <= taban, mod <= 10^9
0 <= us <= 10^9

Example Execution Walkthrough

taban = 2, us = 10, mod = 1000 -> 2^10 = 1024 -> 1024 % 1000 = 24

Example Test Scenarios (3)

Example 1
Input:[2,10,1000]
Expected Output:24
Example 2: 0. Kuvvet
Input:[3,0,7]
Expected Output:1
Example 3: 125 % 13 = 8
Input:[5,3,13]
Expected Output:8
Loading Python Editor...
Input Parameters
[
  2,
  10,
  1000
]
Expected Output
24