{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Problem 6:\n", "\n", "[Euler Project #6](https://projecteuler.net/problem=6)\n", "\n", "> *The sum of the squares of the first ten natural numbers is,\n", "1^2+2^2+...+10^2=385\n", "\n", ">The square of the sum of the first ten natural numbers is,\n", "(1+2+...+10)^2=55^2=3025\n", "\n", ">Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025−385=2640.\n", "\n", ">Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.*\n", "\n", "---" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Reserved Space For Imports\n", "---" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import os\n", "import pprint\n", "import time # Typically imported for sleep function, to slow down execution in terminal.\n", "import typing\n", "import decorators # Typically imported to compute execution duration of functions.\n", "import numpy" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Reserved Space For Method Definition\n", "---" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "def sum_of_squares(i: int,j: int):\n", " '''\n", " Function that computes the sum of a series of squared integers.\n", " '''\n", " series = [k**2 for k in range(i,j+1)]\n", " #pprint.pprint(series)\n", " summ = sum(series)\n", " return summ" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "def square_of_sum(m: int,n: int):\n", " '''\n", " Function that computes the square of a summation of a series of integers.\n", " '''\n", " series = [p for p in range(m,n+1)]\n", " summ = sum(series)**2\n", " #print(summ)\n", " return summ" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1. Begin with testing the problem statement's example case.\n", "---" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "*Mathematically, the trick is to recognize that this a LCM (Least Common Multiple) problem. The solution is list all the prime factors of each number in the factor list, then compute their collective product.*\n", "\n", " - [ ] Create a method that performs the first computation.\n", " - [ ] Create a method that performs the second computation.\n" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "25164150\n" ] } ], "source": [ "# Receive problem inputs...\n", "smallest_factor = 1\n", "largest_factor = 100\n", "\n", "a = square_of_sum(smallest_factor,largest_factor) - sum_of_squares(smallest_factor,largest_factor)\n", "print(a)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "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.8.2" } }, "nbformat": 4, "nbformat_minor": 4 }