diff --git a/notebooks/problem0047.ipynb b/notebooks/problem0047.ipynb new file mode 100644 index 0000000..4ac513c --- /dev/null +++ b/notebooks/problem0047.ipynb @@ -0,0 +1,77 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "1b6c514b", + "metadata": {}, + "source": [ + "# [Distinct Primes Factors](https://projecteuler.net/problem=47)\n", + "\n", + "The [prime omega function](https://en.wikipedia.org/wiki/Prime_omega_function) $\\omega(n)$ counts the number of distinct prime factors of $n$. SageMath provides this function through the [PARI/GP interface](https://doc.sagemath.org/html/en/reference/interfaces/sage/interfaces/gp.html), but we can also just look at the length of the output of the built-in `factor` function.\n", + "\n", + "See [problem 3](https://projecteuler.net/problem=3) for information on implementing a factorization function." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "49b0126c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "134043" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from itertools import count\n", + "\n", + "def omega(n):\n", + " return len(factor(n))\n", + "\n", + "\n", + "for n in count(1):\n", + " if all(omega(n+k) == 4 for k in (0,1,2,3)):\n", + " break\n", + "\n", + "n" + ] + }, + { + "cell_type": "markdown", + "id": "ebcdb94b", + "metadata": {}, + "source": [ + "## Relevant sequences\n", + "* Number of distinct prime factors: [A001221](https://oeis.org/A001221)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "SageMath 9.5", + "language": "sage", + "name": "sagemath" + }, + "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.11.2" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}