(define (expmod base exp m) (remainder (fast-expt base expt) m)) ; TLDR; O(expt) increase in space and O(log(expt)*expt) increase in time complexity ; The problem with this modular exponentiation procedure is the intermediate ; results grow exponentially large in term of expt. If base is log(m) digits, ; then the intermediate results will require O(log(m)*expt) digits. In addition ; to increasing memory requirements, the multiplications in the calculation ; will take O(log(expt) * expt) or O(expt^2) more time depending on the ; multiplication algorithm used.