You are viewing a single comment's thread. Return to all comments →
def solve(a, n, m): a = a % m pow10 = 10 ** len(str(a)) % m answer = 0 while n: if n & 1: #ie n is odd number answer = ((answer * pow10) % m + a) % m a = ((a * pow10) % m + a) % m pow10 = (pow10 * pow10) % m n >>= 1 return answer
https://www.rookieslab.com/posts/fast-power-algorithm-exponentiation-by-squaring-cpp-python-implementation
Seems like cookies are disabled on this browser, please enable them to open this website
Eugene and Big Number
You are viewing a single comment's thread. Return to all comments →