solving large numbers by using modular arithmetic and exponentiation by squaring in python
main.py
defmod_exp(base, exp, mod): result = 1 base = base % mod
while exp > 0:
if exp % 2 == 1:
result = (result * base) % mod
exp = exp >> 1 base = (base * base) % mod
return result
base = 123456789exp = 987654321mod = 10**9 + 7result = mod_exp(base, exp, mod)
print(result)