Connection
Base URL, credentials and a reachable server.
Compute an integer power modulo a positive integer with repeated squaring.
Base URL, credentials and a reachable server.
A model available through the configured endpoint.
Context limits and tool support are determined by the model and server.
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