euler/ipython/EulerProblem029.ipynb

73 lines
1.6 KiB
Plaintext
Executable File

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Euler Problem 29\n",
"\n",
"Consider all integer combinations of ab for 2 ≤ a ≤ 5 and 2 ≤ b ≤ 5:\n",
"\n",
"$2^2=4, 2^3=8, 2^4=16, 2^5=32$\n",
"\n",
"$3^2=9, 3^3=27, 3^4=81, 3^5=243$\n",
"\n",
"$4^2=16, 4^3=64, 4^4=256, 4^5=1024$\n",
"\n",
"$5^2=25, 5^3=125, 5^4=625, 5^5=3125$\n",
"\n",
"If they are then placed in numerical order, with any repeats removed, we get the following sequence of 15 distinct terms:\n",
"\n",
"$4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125$\n",
"\n",
"How many distinct terms are in the sequence generated by $a^b$ for $2 ≤ a ≤ 100$ and $2 ≤ b ≤ 100$?"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"9183\n"
]
}
],
"source": [
"s = len(set([a**b for a in range(2, 101) for b in range(2, 101)]))\n",
"assert(s == 9183)\n",
"print(s)"
]
}
],
"metadata": {
"comopletion_date": "Fri, 25 Aug 2017, 10:03",
"kernelspec": {
"display_name": "Python 3",
"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.6.3"
},
"tags": [
"distinct",
"powers"
]
},
"nbformat": 4,
"nbformat_minor": 2
}