def cal_mod(dividend, divisor): # check the max divisor power of the dividend dividend_power = 1 while dividend > (divisor ** dividend_power) : dividend_power += 1 # reduce the dividend to the divisor_power + 1 # if dividend_power is greater then 2 if dividend_power > 2: while dividend > (divisor ** 2): dividend = cal_mod(dividend, (divisor ** (dividend_power - 1) )) dividend_power -= 1 while dividend >= divisor: dividend = dividend - divisor return dividend result = cal_mod(45645664566465456456878756765675699788866264623874682464, 16) print(result)
Comments