26 lines
482 B
Python
26 lines
482 B
Python
# HumanEval/49
|
|
# Loki Mode Multi-Agent Solution
|
|
# Attempts: 1
|
|
# Passed: True
|
|
|
|
def modp(n: int, p: int):
|
|
"""Return 2^n modulo p (be aware of numerics).
|
|
>>> modp(3, 5)
|
|
3
|
|
>>> modp(1101, 101)
|
|
2
|
|
>>> modp(0, 101)
|
|
1
|
|
>>> modp(3, 11)
|
|
8
|
|
>>> modp(100, 101)
|
|
1
|
|
"""
|
|
result = 1
|
|
base = 2 % p
|
|
while n > 0:
|
|
if n % 2 == 1:
|
|
result = (result * base) % p
|
|
n = n // 2
|
|
base = (base * base) % p
|
|
return result |