Added mathematically correct mod-expt that uses O(1) memory and takes O(log e) time