MModuloSprig
Product

Product features · Integer modular exponentiation

01

Compute an integer power modulo a positive integer with repeated squaring.

01

Connection

Base URL, credentials and a reachable server.

02

Selection

A model available through the configured endpoint.

03

Capabilities

Context limits and tool support are determined by the model and server.

Integer modular exponentiation

● ● ●ModuloSprig●
A concrete starting point · Integer modular exponentiation ×
def mod_power(base, exponent, modulus):
    if any(type(v) is not int for v in (base, exponent, modulus)):
        raise ValueError("operand.integer")
    if exponent < 0 or modulus <= 0:
        raise ValueError("operand.range")
    result = 1 % modulus
    base %= modulus
    while exponent:
        if exponent & 1:
            result = result * base % modulus
        base = base * base % modulus
        exponent >>= 1
    return result
✳Compute an integer power modulo a positive integer with repeated squaring.
✓ ChangesReview before applying ↗
Illustrative workspace
AI coding workspace

Your next change starts here.

Get the Windows app ↗