Memoize powers and improve digest_int/1

Thanks @madlep