Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

x =
n =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

Fast exponentiation by squaring.

Approach

Use binary exponentiation:

  • If n negative, invert x and make n positive.
  • Multiply result by x when current bit is 1.
  • Square x each step.
Code
Loading...
Complexity
Time: O(log |n|)
Space: O(1)
Solution
Updated: 2026-02-23

Idea

Fast exponentiation by squaring.

Approach

Use binary exponentiation:

  • If n negative, invert x and make n positive.
  • Multiply result by x when current bit is 1.
  • Square x each step.
Code
Loading...
Complexity
Time: O(log |n|)
Space: O(1)