```python
%config InlineBackend.figure_format = 'retina'
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
```

# Product of 4 consecutive numbers is always 1 less than a perfect square


<p>
<center>Shubhanshu Mishra (<a href="https://shubhanshu.com">shubhanshu.com</a>)</center>

 
    
</p>

For every $n \in \mathbb{Z}$, we can have 4 consecutive numbers as follows:

$
n, n+1, n+2, n+3
$

We can complete the proof, if we can show that there exists a $k \in \mathbb{Z}$, such that the following equation holds:

$
\begin{equation}
n*(n+1)*(n+2)*(n+3) = (k^2 - 1)
\end{equation}
$



```python
i_max = 4
nums = np.arange(0, 50)+1
consecutive_nums = np.stack([
    np.roll(nums, -i)
    for i in range(i_max)
], axis=1)[:-i_max+1]
n_prods = consecutive_nums.prod(axis=1)
df = pd.DataFrame(consecutive_nums, columns=[f"n{i+1}" for i in range(i_max)])
df["prod"] = n_prods
df["k"] = np.sqrt(n_prods+1).astype(int)
df["k^2"] = df["k"]**2
df["k^2 - 1"] = df["k^2"] - 1
df
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>n1</th>
      <th>n2</th>
      <th>n3</th>
      <th>n4</th>
      <th>prod</th>
      <th>k</th>
      <th>k^2</th>
      <th>k^2 - 1</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>1</td>
      <td>2</td>
      <td>3</td>
      <td>4</td>
      <td>24</td>
      <td>5</td>
      <td>25</td>
      <td>24</td>
    </tr>
    <tr>
      <th>1</th>
      <td>2</td>
      <td>3</td>
      <td>4</td>
      <td>5</td>
      <td>120</td>
      <td>11</td>
      <td>121</td>
      <td>120</td>
    </tr>
    <tr>
      <th>2</th>
      <td>3</td>
      <td>4</td>
      <td>5</td>
      <td>6</td>
      <td>360</td>
      <td>19</td>
      <td>361</td>
      <td>360</td>
    </tr>
    <tr>
      <th>3</th>
      <td>4</td>
      <td>5</td>
      <td>6</td>
      <td>7</td>
      <td>840</td>
      <td>29</td>
      <td>841</td>
      <td>840</td>
    </tr>
    <tr>
      <th>4</th>
      <td>5</td>
      <td>6</td>
      <td>7</td>
      <td>8</td>
      <td>1680</td>
      <td>41</td>
      <td>1681</td>
      <td>1680</td>
    </tr>
    <tr>
      <th>5</th>
      <td>6</td>
      <td>7</td>
      <td>8</td>
      <td>9</td>
      <td>3024</td>
      <td>55</td>
      <td>3025</td>
      <td>3024</td>
    </tr>
    <tr>
      <th>6</th>
      <td>7</td>
      <td>8</td>
      <td>9</td>
      <td>10</td>
      <td>5040</td>
      <td>71</td>
      <td>5041</td>
      <td>5040</td>
    </tr>
    <tr>
      <th>7</th>
      <td>8</td>
      <td>9</td>
      <td>10</td>
      <td>11</td>
      <td>7920</td>
      <td>89</td>
      <td>7921</td>
      <td>7920</td>
    </tr>
    <tr>
      <th>8</th>
      <td>9</td>
      <td>10</td>
      <td>11</td>
      <td>12</td>
      <td>11880</td>
      <td>109</td>
      <td>11881</td>
      <td>11880</td>
    </tr>
    <tr>
      <th>9</th>
      <td>10</td>
      <td>11</td>
      <td>12</td>
      <td>13</td>
      <td>17160</td>
      <td>131</td>
      <td>17161</td>
      <td>17160</td>
    </tr>
    <tr>
      <th>10</th>
      <td>11</td>
      <td>12</td>
      <td>13</td>
      <td>14</td>
      <td>24024</td>
      <td>155</td>
      <td>24025</td>
      <td>24024</td>
    </tr>
    <tr>
      <th>11</th>
      <td>12</td>
      <td>13</td>
      <td>14</td>
      <td>15</td>
      <td>32760</td>
      <td>181</td>
      <td>32761</td>
      <td>32760</td>
    </tr>
    <tr>
      <th>12</th>
      <td>13</td>
      <td>14</td>
      <td>15</td>
      <td>16</td>
      <td>43680</td>
      <td>209</td>
      <td>43681</td>
      <td>43680</td>
    </tr>
    <tr>
      <th>13</th>
      <td>14</td>
      <td>15</td>
      <td>16</td>
      <td>17</td>
      <td>57120</td>
      <td>239</td>
      <td>57121</td>
      <td>57120</td>
    </tr>
    <tr>
      <th>14</th>
      <td>15</td>
      <td>16</td>
      <td>17</td>
      <td>18</td>
      <td>73440</td>
      <td>271</td>
      <td>73441</td>
      <td>73440</td>
    </tr>
    <tr>
      <th>15</th>
      <td>16</td>
      <td>17</td>
      <td>18</td>
      <td>19</td>
      <td>93024</td>
      <td>305</td>
      <td>93025</td>
      <td>93024</td>
    </tr>
    <tr>
      <th>16</th>
      <td>17</td>
      <td>18</td>
      <td>19</td>
      <td>20</td>
      <td>116280</td>
      <td>341</td>
      <td>116281</td>
      <td>116280</td>
    </tr>
    <tr>
      <th>17</th>
      <td>18</td>
      <td>19</td>
      <td>20</td>
      <td>21</td>
      <td>143640</td>
      <td>379</td>
      <td>143641</td>
      <td>143640</td>
    </tr>
    <tr>
      <th>18</th>
      <td>19</td>
      <td>20</td>
      <td>21</td>
      <td>22</td>
      <td>175560</td>
      <td>419</td>
      <td>175561</td>
      <td>175560</td>
    </tr>
    <tr>
      <th>19</th>
      <td>20</td>
      <td>21</td>
      <td>22</td>
      <td>23</td>
      <td>212520</td>
      <td>461</td>
      <td>212521</td>
      <td>212520</td>
    </tr>
    <tr>
      <th>20</th>
      <td>21</td>
      <td>22</td>
      <td>23</td>
      <td>24</td>
      <td>255024</td>
      <td>505</td>
      <td>255025</td>
      <td>255024</td>
    </tr>
    <tr>
      <th>21</th>
      <td>22</td>
      <td>23</td>
      <td>24</td>
      <td>25</td>
      <td>303600</td>
      <td>551</td>
      <td>303601</td>
      <td>303600</td>
    </tr>
    <tr>
      <th>22</th>
      <td>23</td>
      <td>24</td>
      <td>25</td>
      <td>26</td>
      <td>358800</td>
      <td>599</td>
      <td>358801</td>
      <td>358800</td>
    </tr>
    <tr>
      <th>23</th>
      <td>24</td>
      <td>25</td>
      <td>26</td>
      <td>27</td>
      <td>421200</td>
      <td>649</td>
      <td>421201</td>
      <td>421200</td>
    </tr>
    <tr>
      <th>24</th>
      <td>25</td>
      <td>26</td>
      <td>27</td>
      <td>28</td>
      <td>491400</td>
      <td>701</td>
      <td>491401</td>
      <td>491400</td>
    </tr>
    <tr>
      <th>25</th>
      <td>26</td>
      <td>27</td>
      <td>28</td>
      <td>29</td>
      <td>570024</td>
      <td>755</td>
      <td>570025</td>
      <td>570024</td>
    </tr>
    <tr>
      <th>26</th>
      <td>27</td>
      <td>28</td>
      <td>29</td>
      <td>30</td>
      <td>657720</td>
      <td>811</td>
      <td>657721</td>
      <td>657720</td>
    </tr>
    <tr>
      <th>27</th>
      <td>28</td>
      <td>29</td>
      <td>30</td>
      <td>31</td>
      <td>755160</td>
      <td>869</td>
      <td>755161</td>
      <td>755160</td>
    </tr>
    <tr>
      <th>28</th>
      <td>29</td>
      <td>30</td>
      <td>31</td>
      <td>32</td>
      <td>863040</td>
      <td>929</td>
      <td>863041</td>
      <td>863040</td>
    </tr>
    <tr>
      <th>29</th>
      <td>30</td>
      <td>31</td>
      <td>32</td>
      <td>33</td>
      <td>982080</td>
      <td>991</td>
      <td>982081</td>
      <td>982080</td>
    </tr>
    <tr>
      <th>30</th>
      <td>31</td>
      <td>32</td>
      <td>33</td>
      <td>34</td>
      <td>1113024</td>
      <td>1055</td>
      <td>1113025</td>
      <td>1113024</td>
    </tr>
    <tr>
      <th>31</th>
      <td>32</td>
      <td>33</td>
      <td>34</td>
      <td>35</td>
      <td>1256640</td>
      <td>1121</td>
      <td>1256641</td>
      <td>1256640</td>
    </tr>
    <tr>
      <th>32</th>
      <td>33</td>
      <td>34</td>
      <td>35</td>
      <td>36</td>
      <td>1413720</td>
      <td>1189</td>
      <td>1413721</td>
      <td>1413720</td>
    </tr>
    <tr>
      <th>33</th>
      <td>34</td>
      <td>35</td>
      <td>36</td>
      <td>37</td>
      <td>1585080</td>
      <td>1259</td>
      <td>1585081</td>
      <td>1585080</td>
    </tr>
    <tr>
      <th>34</th>
      <td>35</td>
      <td>36</td>
      <td>37</td>
      <td>38</td>
      <td>1771560</td>
      <td>1331</td>
      <td>1771561</td>
      <td>1771560</td>
    </tr>
    <tr>
      <th>35</th>
      <td>36</td>
      <td>37</td>
      <td>38</td>
      <td>39</td>
      <td>1974024</td>
      <td>1405</td>
      <td>1974025</td>
      <td>1974024</td>
    </tr>
    <tr>
      <th>36</th>
      <td>37</td>
      <td>38</td>
      <td>39</td>
      <td>40</td>
      <td>2193360</td>
      <td>1481</td>
      <td>2193361</td>
      <td>2193360</td>
    </tr>
    <tr>
      <th>37</th>
      <td>38</td>
      <td>39</td>
      <td>40</td>
      <td>41</td>
      <td>2430480</td>
      <td>1559</td>
      <td>2430481</td>
      <td>2430480</td>
    </tr>
    <tr>
      <th>38</th>
      <td>39</td>
      <td>40</td>
      <td>41</td>
      <td>42</td>
      <td>2686320</td>
      <td>1639</td>
      <td>2686321</td>
      <td>2686320</td>
    </tr>
    <tr>
      <th>39</th>
      <td>40</td>
      <td>41</td>
      <td>42</td>
      <td>43</td>
      <td>2961840</td>
      <td>1721</td>
      <td>2961841</td>
      <td>2961840</td>
    </tr>
    <tr>
      <th>40</th>
      <td>41</td>
      <td>42</td>
      <td>43</td>
      <td>44</td>
      <td>3258024</td>
      <td>1805</td>
      <td>3258025</td>
      <td>3258024</td>
    </tr>
    <tr>
      <th>41</th>
      <td>42</td>
      <td>43</td>
      <td>44</td>
      <td>45</td>
      <td>3575880</td>
      <td>1891</td>
      <td>3575881</td>
      <td>3575880</td>
    </tr>
    <tr>
      <th>42</th>
      <td>43</td>
      <td>44</td>
      <td>45</td>
      <td>46</td>
      <td>3916440</td>
      <td>1979</td>
      <td>3916441</td>
      <td>3916440</td>
    </tr>
    <tr>
      <th>43</th>
      <td>44</td>
      <td>45</td>
      <td>46</td>
      <td>47</td>
      <td>4280760</td>
      <td>2069</td>
      <td>4280761</td>
      <td>4280760</td>
    </tr>
    <tr>
      <th>44</th>
      <td>45</td>
      <td>46</td>
      <td>47</td>
      <td>48</td>
      <td>4669920</td>
      <td>2161</td>
      <td>4669921</td>
      <td>4669920</td>
    </tr>
    <tr>
      <th>45</th>
      <td>46</td>
      <td>47</td>
      <td>48</td>
      <td>49</td>
      <td>5085024</td>
      <td>2255</td>
      <td>5085025</td>
      <td>5085024</td>
    </tr>
    <tr>
      <th>46</th>
      <td>47</td>
      <td>48</td>
      <td>49</td>
      <td>50</td>
      <td>5527200</td>
      <td>2351</td>
      <td>5527201</td>
      <td>5527200</td>
    </tr>
  </tbody>
</table>
</div>




```python
fig, ax = plt.subplots(1,3, figsize=(18, 6))

ax[0].plot("n1", "prod", "bo-", data=df)
ax[0].set_xlabel("n", fontsize=20)
ax[0].set_ylabel(f"$y = \prod_{{i=0}}^{{i={i_max}}} (n+i)$", fontsize=20)

ax[1].plot(df["k"], df["prod"], "ko-")
ax[1].set_xlabel("$k = \sqrt{y + 1}$", fontsize=20)
ax[1].set_title("$y = k^2 - 1$", fontsize=20)


ax[2].plot(df["n1"], df["k"], "ko-")
ax[2].set_ylabel("$k = \sqrt{y + 1}$", fontsize=20)
ax[2].set_xlabel("$n$", fontsize=20)

fig.tight_layout()
```

Let us look at the right hand side of the equation first, i.e. $k^2 - 1$.

This can be rewritten as $\textbf{(k-1)*(k+1)}$

**Now, this is where a hint lies.**

What the right hand side means that it is a product of two integers ($k-1$ and $k+1$) which differ by 2. 

We can see that this is the case:

$
\begin{equation}
(k+1) - (k-1) \\
= k + 1 - k - (-1) \\
= k - k + 1 - (-1) \\
= 0 + 1 + 1 \\
= 2 \\
\end{equation}
$

So, if we can somehow show that the left hand side of the original equation, i.e. $n*(n+1)*(n+2)*(n+3)$:

* can be represented as a product of two numbers which differ by 2, then we are done, 
* as these numbers can then be mapped to $k-1$ and $k+1$ for some $k \in \mathbb{Z}$.

We can group the numbers $\textbf{n, n+1, n+2, n+3}$ into pairs, with the hope of getting $k-1$ and $k+1$.

We can utilize following facts to choose the two pairs:

* The difference of the products should be constant, and hence independent of $n$
* Knowing that product of two factors of type $(n+i)*(n+j) = n^2 + (i+j)*n + i*j$,
* We can observe that $i+j$ will be same for numbers which are equidistant from the middle of all numbers.

Now we can select our pair of numbers.

* The first pair is $n$ and $(n+3)$, 
    * and their product is $\textbf{n * (n+3)}$ 
    * which can be expanded as $\color{red}{\textbf{n^2 + 3n}}$

* And, the second pair $(n+1)$ and $(n+2)$, 
    * and their product is $\textbf{(n+1)*(n+2)}$ 
    * which can be expanded as $\color{red}{\textbf{n^2 + 3n}} + \textbf{2}$

Based on the above pairing we can immediately see that the difference of these pair products is as follows:

$
\begin{equation}
[(n+1)*(n+2)] - [n * (n+3)]\\
= [\color{red}{n^2 + 3n} + 2] - [\color{red}{n^2 + 3n}]\\
= n^2 + 3n + 2 - n^2 - 3n\\
= (n^2 -n^2) + (3n - 3n) + 2\\
= 0 + 0 + 2\\
= 2
\end{equation}
$

Hence, based on the above simplification, we can map: 

* $(\color{red}{n^2 + 3n} + 2) \rightarrow (k+1)$, and 
* $(\color{red}{n^2 + 3n}) \rightarrow (k-1)$. 

Now, if we choose $\color{blue}{\textbf{k = (n^2 + 3n + 1)}}$, the following equations hold: 

* $n^2 + 3n + 2 = \color{blue}{(n^2 + 3n + 1)} + 1 = \color{blue}{k} + 1$

* $n^2 + 3n = \color{blue}{(n^2 + 3n + 1)} - 1 = \color{blue}{k} - 1$

Hence, we have proved the following:

$
\begin{equation}
\forall n \in \mathbb{Z}, \\
\exists k \in \mathbb{Z} \\
n*(n+1)*(n+2)*(n+3) \\
= [(n+3)*n]*[(n+1)*(n+2)]\\
= [\color{red}{n^2 + 3n}]*[\color{red}{n^2 + 3n} + 2]\\
= [\color{blue}{(n^2 + 3n + 1)} - 1]*[\color{blue}{(n^2 + 3n + 1)} + 1]\\
= [\color{blue}{k} - 1]*[\color{blue}{k} + 1]\\
= (k^2 - 1)
\end{equation}
$

And this equation can be solved by choosing $\color{blue}{\textbf{k = (n^2 + 3n + 1)}}$.

Hence, proved.


```python
df["k = n^2 + 3n + 1"] = (df["n1"]**2 + 3*df["n1"] + 1)
df
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>n1</th>
      <th>n2</th>
      <th>n3</th>
      <th>n4</th>
      <th>prod</th>
      <th>k</th>
      <th>k^2</th>
      <th>k^2 - 1</th>
      <th>k = n^2 + 3n + 1</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>1</td>
      <td>2</td>
      <td>3</td>
      <td>4</td>
      <td>24</td>
      <td>5</td>
      <td>25</td>
      <td>24</td>
      <td>5</td>
    </tr>
    <tr>
      <th>1</th>
      <td>2</td>
      <td>3</td>
      <td>4</td>
      <td>5</td>
      <td>120</td>
      <td>11</td>
      <td>121</td>
      <td>120</td>
      <td>11</td>
    </tr>
    <tr>
      <th>2</th>
      <td>3</td>
      <td>4</td>
      <td>5</td>
      <td>6</td>
      <td>360</td>
      <td>19</td>
      <td>361</td>
      <td>360</td>
      <td>19</td>
    </tr>
    <tr>
      <th>3</th>
      <td>4</td>
      <td>5</td>
      <td>6</td>
      <td>7</td>
      <td>840</td>
      <td>29</td>
      <td>841</td>
      <td>840</td>
      <td>29</td>
    </tr>
    <tr>
      <th>4</th>
      <td>5</td>
      <td>6</td>
      <td>7</td>
      <td>8</td>
      <td>1680</td>
      <td>41</td>
      <td>1681</td>
      <td>1680</td>
      <td>41</td>
    </tr>
    <tr>
      <th>5</th>
      <td>6</td>
      <td>7</td>
      <td>8</td>
      <td>9</td>
      <td>3024</td>
      <td>55</td>
      <td>3025</td>
      <td>3024</td>
      <td>55</td>
    </tr>
    <tr>
      <th>6</th>
      <td>7</td>
      <td>8</td>
      <td>9</td>
      <td>10</td>
      <td>5040</td>
      <td>71</td>
      <td>5041</td>
      <td>5040</td>
      <td>71</td>
    </tr>
    <tr>
      <th>7</th>
      <td>8</td>
      <td>9</td>
      <td>10</td>
      <td>11</td>
      <td>7920</td>
      <td>89</td>
      <td>7921</td>
      <td>7920</td>
      <td>89</td>
    </tr>
    <tr>
      <th>8</th>
      <td>9</td>
      <td>10</td>
      <td>11</td>
      <td>12</td>
      <td>11880</td>
      <td>109</td>
      <td>11881</td>
      <td>11880</td>
      <td>109</td>
    </tr>
    <tr>
      <th>9</th>
      <td>10</td>
      <td>11</td>
      <td>12</td>
      <td>13</td>
      <td>17160</td>
      <td>131</td>
      <td>17161</td>
      <td>17160</td>
      <td>131</td>
    </tr>
    <tr>
      <th>10</th>
      <td>11</td>
      <td>12</td>
      <td>13</td>
      <td>14</td>
      <td>24024</td>
      <td>155</td>
      <td>24025</td>
      <td>24024</td>
      <td>155</td>
    </tr>
    <tr>
      <th>11</th>
      <td>12</td>
      <td>13</td>
      <td>14</td>
      <td>15</td>
      <td>32760</td>
      <td>181</td>
      <td>32761</td>
      <td>32760</td>
      <td>181</td>
    </tr>
    <tr>
      <th>12</th>
      <td>13</td>
      <td>14</td>
      <td>15</td>
      <td>16</td>
      <td>43680</td>
      <td>209</td>
      <td>43681</td>
      <td>43680</td>
      <td>209</td>
    </tr>
    <tr>
      <th>13</th>
      <td>14</td>
      <td>15</td>
      <td>16</td>
      <td>17</td>
      <td>57120</td>
      <td>239</td>
      <td>57121</td>
      <td>57120</td>
      <td>239</td>
    </tr>
    <tr>
      <th>14</th>
      <td>15</td>
      <td>16</td>
      <td>17</td>
      <td>18</td>
      <td>73440</td>
      <td>271</td>
      <td>73441</td>
      <td>73440</td>
      <td>271</td>
    </tr>
    <tr>
      <th>15</th>
      <td>16</td>
      <td>17</td>
      <td>18</td>
      <td>19</td>
      <td>93024</td>
      <td>305</td>
      <td>93025</td>
      <td>93024</td>
      <td>305</td>
    </tr>
    <tr>
      <th>16</th>
      <td>17</td>
      <td>18</td>
      <td>19</td>
      <td>20</td>
      <td>116280</td>
      <td>341</td>
      <td>116281</td>
      <td>116280</td>
      <td>341</td>
    </tr>
    <tr>
      <th>17</th>
      <td>18</td>
      <td>19</td>
      <td>20</td>
      <td>21</td>
      <td>143640</td>
      <td>379</td>
      <td>143641</td>
      <td>143640</td>
      <td>379</td>
    </tr>
    <tr>
      <th>18</th>
      <td>19</td>
      <td>20</td>
      <td>21</td>
      <td>22</td>
      <td>175560</td>
      <td>419</td>
      <td>175561</td>
      <td>175560</td>
      <td>419</td>
    </tr>
    <tr>
      <th>19</th>
      <td>20</td>
      <td>21</td>
      <td>22</td>
      <td>23</td>
      <td>212520</td>
      <td>461</td>
      <td>212521</td>
      <td>212520</td>
      <td>461</td>
    </tr>
    <tr>
      <th>20</th>
      <td>21</td>
      <td>22</td>
      <td>23</td>
      <td>24</td>
      <td>255024</td>
      <td>505</td>
      <td>255025</td>
      <td>255024</td>
      <td>505</td>
    </tr>
    <tr>
      <th>21</th>
      <td>22</td>
      <td>23</td>
      <td>24</td>
      <td>25</td>
      <td>303600</td>
      <td>551</td>
      <td>303601</td>
      <td>303600</td>
      <td>551</td>
    </tr>
    <tr>
      <th>22</th>
      <td>23</td>
      <td>24</td>
      <td>25</td>
      <td>26</td>
      <td>358800</td>
      <td>599</td>
      <td>358801</td>
      <td>358800</td>
      <td>599</td>
    </tr>
    <tr>
      <th>23</th>
      <td>24</td>
      <td>25</td>
      <td>26</td>
      <td>27</td>
      <td>421200</td>
      <td>649</td>
      <td>421201</td>
      <td>421200</td>
      <td>649</td>
    </tr>
    <tr>
      <th>24</th>
      <td>25</td>
      <td>26</td>
      <td>27</td>
      <td>28</td>
      <td>491400</td>
      <td>701</td>
      <td>491401</td>
      <td>491400</td>
      <td>701</td>
    </tr>
    <tr>
      <th>25</th>
      <td>26</td>
      <td>27</td>
      <td>28</td>
      <td>29</td>
      <td>570024</td>
      <td>755</td>
      <td>570025</td>
      <td>570024</td>
      <td>755</td>
    </tr>
    <tr>
      <th>26</th>
      <td>27</td>
      <td>28</td>
      <td>29</td>
      <td>30</td>
      <td>657720</td>
      <td>811</td>
      <td>657721</td>
      <td>657720</td>
      <td>811</td>
    </tr>
    <tr>
      <th>27</th>
      <td>28</td>
      <td>29</td>
      <td>30</td>
      <td>31</td>
      <td>755160</td>
      <td>869</td>
      <td>755161</td>
      <td>755160</td>
      <td>869</td>
    </tr>
    <tr>
      <th>28</th>
      <td>29</td>
      <td>30</td>
      <td>31</td>
      <td>32</td>
      <td>863040</td>
      <td>929</td>
      <td>863041</td>
      <td>863040</td>
      <td>929</td>
    </tr>
    <tr>
      <th>29</th>
      <td>30</td>
      <td>31</td>
      <td>32</td>
      <td>33</td>
      <td>982080</td>
      <td>991</td>
      <td>982081</td>
      <td>982080</td>
      <td>991</td>
    </tr>
    <tr>
      <th>30</th>
      <td>31</td>
      <td>32</td>
      <td>33</td>
      <td>34</td>
      <td>1113024</td>
      <td>1055</td>
      <td>1113025</td>
      <td>1113024</td>
      <td>1055</td>
    </tr>
    <tr>
      <th>31</th>
      <td>32</td>
      <td>33</td>
      <td>34</td>
      <td>35</td>
      <td>1256640</td>
      <td>1121</td>
      <td>1256641</td>
      <td>1256640</td>
      <td>1121</td>
    </tr>
    <tr>
      <th>32</th>
      <td>33</td>
      <td>34</td>
      <td>35</td>
      <td>36</td>
      <td>1413720</td>
      <td>1189</td>
      <td>1413721</td>
      <td>1413720</td>
      <td>1189</td>
    </tr>
    <tr>
      <th>33</th>
      <td>34</td>
      <td>35</td>
      <td>36</td>
      <td>37</td>
      <td>1585080</td>
      <td>1259</td>
      <td>1585081</td>
      <td>1585080</td>
      <td>1259</td>
    </tr>
    <tr>
      <th>34</th>
      <td>35</td>
      <td>36</td>
      <td>37</td>
      <td>38</td>
      <td>1771560</td>
      <td>1331</td>
      <td>1771561</td>
      <td>1771560</td>
      <td>1331</td>
    </tr>
    <tr>
      <th>35</th>
      <td>36</td>
      <td>37</td>
      <td>38</td>
      <td>39</td>
      <td>1974024</td>
      <td>1405</td>
      <td>1974025</td>
      <td>1974024</td>
      <td>1405</td>
    </tr>
    <tr>
      <th>36</th>
      <td>37</td>
      <td>38</td>
      <td>39</td>
      <td>40</td>
      <td>2193360</td>
      <td>1481</td>
      <td>2193361</td>
      <td>2193360</td>
      <td>1481</td>
    </tr>
    <tr>
      <th>37</th>
      <td>38</td>
      <td>39</td>
      <td>40</td>
      <td>41</td>
      <td>2430480</td>
      <td>1559</td>
      <td>2430481</td>
      <td>2430480</td>
      <td>1559</td>
    </tr>
    <tr>
      <th>38</th>
      <td>39</td>
      <td>40</td>
      <td>41</td>
      <td>42</td>
      <td>2686320</td>
      <td>1639</td>
      <td>2686321</td>
      <td>2686320</td>
      <td>1639</td>
    </tr>
    <tr>
      <th>39</th>
      <td>40</td>
      <td>41</td>
      <td>42</td>
      <td>43</td>
      <td>2961840</td>
      <td>1721</td>
      <td>2961841</td>
      <td>2961840</td>
      <td>1721</td>
    </tr>
    <tr>
      <th>40</th>
      <td>41</td>
      <td>42</td>
      <td>43</td>
      <td>44</td>
      <td>3258024</td>
      <td>1805</td>
      <td>3258025</td>
      <td>3258024</td>
      <td>1805</td>
    </tr>
    <tr>
      <th>41</th>
      <td>42</td>
      <td>43</td>
      <td>44</td>
      <td>45</td>
      <td>3575880</td>
      <td>1891</td>
      <td>3575881</td>
      <td>3575880</td>
      <td>1891</td>
    </tr>
    <tr>
      <th>42</th>
      <td>43</td>
      <td>44</td>
      <td>45</td>
      <td>46</td>
      <td>3916440</td>
      <td>1979</td>
      <td>3916441</td>
      <td>3916440</td>
      <td>1979</td>
    </tr>
    <tr>
      <th>43</th>
      <td>44</td>
      <td>45</td>
      <td>46</td>
      <td>47</td>
      <td>4280760</td>
      <td>2069</td>
      <td>4280761</td>
      <td>4280760</td>
      <td>2069</td>
    </tr>
    <tr>
      <th>44</th>
      <td>45</td>
      <td>46</td>
      <td>47</td>
      <td>48</td>
      <td>4669920</td>
      <td>2161</td>
      <td>4669921</td>
      <td>4669920</td>
      <td>2161</td>
    </tr>
    <tr>
      <th>45</th>
      <td>46</td>
      <td>47</td>
      <td>48</td>
      <td>49</td>
      <td>5085024</td>
      <td>2255</td>
      <td>5085025</td>
      <td>5085024</td>
      <td>2255</td>
    </tr>
    <tr>
      <th>46</th>
      <td>47</td>
      <td>48</td>
      <td>49</td>
      <td>50</td>
      <td>5527200</td>
      <td>2351</td>
      <td>5527201</td>
      <td>5527200</td>
      <td>2351</td>
    </tr>
  </tbody>
</table>
</div>




```python
fig, ax = plt.subplots(1,3, figsize=(12, 6))

ax[0].plot("n1", "prod", "bo-", data=df)
ax[0].set_xlabel("n", fontsize=20)
ax[0].set_ylabel(f"$y = \prod_{{i=0}}^{{i={i_max}}} (n+i)$", fontsize=20)

ax[1].plot(df["k"], df["prod"], "ko-")
ax[1].set_xlabel("$k = \sqrt{y + 1}$", fontsize=20)
ax[1].set_title("$y = k^2 - 1$", fontsize=20)


ax[2].plot(df["n1"], df["k"], "ko-", label="$k = \sqrt{y + 1}$")
ax[2].plot(df["n1"], df["k = n^2 + 3n + 1"], "r--", label="$k = n^2 + 3n + 1$")
ax[2].legend(fontsize=14)

ax[2].set_ylabel("$k = \sqrt{y + 1}$", fontsize=20)
ax[2].set_xlabel("$n$", fontsize=20)

fig.tight_layout()
```

# More videos to come


<p>
<center>Shubhanshu Mishra (<a href="https://shubhanshu.com">shubhanshu.com</a>)</center>

 
    
</p>


```python
fig, ax = plt.subplots(1,3, figsize=(12, 6))
fig.patch.set_facecolor('white')


ax[0].plot("n1", "prod", "bo-", data=df)
ax[0].set_xlabel("n", fontsize=20)
ax[0].set_ylabel(f"$y = \prod_{{i=0}}^{{i={i_max}}} (n+i)$", fontsize=20)

ax[1].plot(df["k"], df["prod"], "ko-")
ax[1].set_xlabel("$k = \sqrt{y + 1}$", fontsize=20)
ax[1].set_title("$y = k^2 - 1$", fontsize=20)


ax[2].plot(df["n1"], df["k"], "ko-", label="$k = \sqrt{y + 1}$")
ax[2].plot(df["n1"], df["k = n^2 + 3n + 1"], "r--", label="$k = n^2 + 3n + 1$")
ax[2].legend(fontsize=14)

ax[2].set_ylabel("$k = \sqrt{y + 1}$", fontsize=20)
ax[2].set_xlabel("$n$", fontsize=20)


fig.suptitle(f"Product of 4 consecutive integers is 1 less than a perfect square.", fontsize=20)

fig.tight_layout()
```

## Related works


* P. Erdös. J. L. Selfridge. "The product of consecutive integers is never a power." Illinois J. Math. 19 (2) 292 - 301, June 1975. https://doi.org/10.1215/ijm/1256050816

## Visual Proof


```python
nums = np.arange(10,10+4)
A = np.zeros((nums[0], nums[-1]))
A[:, nums[0]:] = 1
sns.heatmap(A, linewidth=2, cbar=False, vmin=0, vmax=4)
```


```python
nums = np.arange(10,10+4)
A = np.zeros((nums[1], nums[2]))
A[:, nums[0]:] = 2
A[nums[0]:, :] = 3
A[nums[0]:, nums[0]:] = 1

sns.heatmap(A, linewidth=2, cbar=False, vmin=0, vmax=4)
```


```python
import matplotlib.animation as animation
from IPython.display import HTML
```


```python
fig, ax = plt.subplots(1,1)
frames = []

nums = np.arange(10,10+4)
A = np.zeros((nums[1], nums[-1]))

im = ax.pcolormesh(A, cmap="inferno", vmin=0, vmax=4)
title = ax.set_title(f"Start")
ax.invert_yaxis()
ax.set_xticks(np.arange(A.shape[1]))
ax.set_yticks(np.arange(A.shape[0]))
ax.grid(which="major", color="w", linestyle='-', linewidth=3)


def init():
    im.set_array(A)
    title.set_text("")
    return im, title

def animate(i):
    text = ""
    if i == 0:
        A[:, nums[0]:] = 4
        A[nums[0]:, :] = 4
        text = "$n * n$"
    if i == 1:
        A[:, nums[0]:] = 2
        A[nums[0]:, ] = 4
        text = "$n * (n+3)$"
    if i == 2:
        A[:, nums[0]:] = 2
        A[:, nums[2]:] = 3
        A[nums[0]:, ] = 4
        text = "$n * (n+3)$"
    if i == 3:
        A[:, nums[2]:] = 4
        A[nums[0]:, :] = 3
        A[nums[0]:, nums[0]:] = 4
        A[nums[0]:, nums[0]:nums[2]] = 4
        text = "$(n+1) * (n+2)$"
    if i == 4:
        A[nums[0]:, nums[0]:nums[2]] = 1
        text = "$n * (n+3) = (n+1)*(n+2) - 2$"
#     print(A)
    im.set_array(A)
    title.set_text(f"Step: {i} | {text}")
    return im, title

# ax = sns.heatmap(A, linewidth=2, cbar=False, vmin=0, vmax=4)

fig.tight_layout()

ani = animation.FuncAnimation(fig,animate,frames=5,interval=2000,blit=True,repeat=True)

HTML(ani.to_html5_video())
# frames
```


```python
# ax.cla()
nums = np.arange(10,10+4)
A = np.zeros((nums[1], nums[-1]))
A[:, nums[0]:] = 2
A[nums[0]:, ] = 4
sns.heatmap(A, linewidth=2, cbar=False, vmin=0, vmax=4)
plt.show()
# plt.pause(1)

A[:, nums[2]:] = 4
sns.heatmap(A, linewidth=2, cbar=False, vmin=0, vmax=4)
plt.show()
# plt.pause(1)

A[nums[0]:, :] = 2
A[nums[0]:, nums[0]:] = 4
A[nums[0]:, nums[0]:nums[2]] = 1
sns.heatmap(A, linewidth=2, cbar=False, vmin=0, vmax=4)
plt.show()
# plt.pause(1)
```


```python
nums = np.arange(10,10+4)
A = np.zeros((nums[1], nums[-1]))
A[:, nums[0]:] = 2
A[nums[0]:, :] = 3
A[nums[0]:, nums[0]:] = 1
A[:, nums[2]:] = 4
sns.heatmap(A, linewidth=2, cbar=False, vmin=0, vmax=4)
```


```python

```

8d7ef2ccb77d6fb479ccc4071141c6aa6b0f7bce
ipynb
Jupyter Notebook
Slide Notebooks/Product of consecutive numbers.ipynb
napsternxg/ipython-notebooks
7f36ddadf32dc8891f95d70c18f54bbed5e5bf78
Apache-2.0
2015-08-04T21:28:12.000Z
2022-03-09T01:16:26.000Z
Slide Notebooks/Product of consecutive numbers.ipynb
napsternxg/ipython-notebooks
7f36ddadf32dc8891f95d70c18f54bbed5e5bf78
Apache-2.0
2016-01-20T09:59:38.000Z
2016-01-20T09:59:38.000Z
Slide Notebooks/Product of consecutive numbers.ipynb
napsternxg/ipython-notebooks
7f36ddadf32dc8891f95d70c18f54bbed5e5bf78
Apache-2.0
2015-08-03T16:31:36.000Z
2021-01-17T02:43:14.000Z
Qwen/Qwen-72B
1. YES
2. YES