Home
About
Resume
Projects
Links
Blog
Download notebook
{ "cells": [ { "cell_type": "markdown", "id": "a469358e-2f57-4bd6-9c8d-c59f3d77920b", "metadata": {}, "source": [ "### Q56\n", "Considering natural numbers of the form, \\( a^b \\), where \\(a, b < 100\\), what is the maximum digital sum?" ] }, { "cell_type": "code", "execution_count": 1, "id": "bd7ddc2f-5964-49c3-a927-774399b0b0a9", "metadata": {}, "outputs": [], "source": [ "def max_digit_sum(max_a, max_b):\n", " return max(sum(int(i) for i in str(a**b)) for a in range(1,max_a) for b in range(1,max_b))" ] }, { "cell_type": "code", "execution_count": 2, "id": "3e78fa42-856e-4722-a279-245d9b8516a5", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CPU times: user 52.7 ms, sys: 277 µs, total: 53 ms\n", "Wall time: 50.9 ms\n" ] }, { "data": { "text/plain": [ "972" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "%%time\n", "max_digit_sum(100,100)" ] }, { "cell_type": "code", "execution_count": null, "id": "b869eac9-8c59-4a32-a226-a1308dec4e4c", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.10" } }, "nbformat": 4, "nbformat_minor": 5 }
Previous Notebook:
Project Euler Q55
Next Notebook:
Project Euler Q57
Loading