Finding longest sequence such that $4k + 1$ is neither prime nor a perfect square What is the largest value of $k$ such that $4k + 1$ produces  maximum consecutive terms which are neither primes nor perfect squares and $k$ is a natural number.
For example, at $k = 16$, we get a sequence of two consecutive terms, 65 and 69 which are neither prime nor square.
One of my friend asked me this question and I am unable to solve it. Can anybody please solve it?
 A: Given any $n>1$, if $M=\left((4n+1)!\right)^2+5$ is of the form $4k+1.$
And $M,M+4,M+8,\dots,M+4(n-1)$ are not prime, and they are not squares, because the next largest square is $\left((4n+1)!+1\right)^2,$ which is $M+2(4n+1)!-4$ and it is easy to see that $2(4n+1)!-4>4(n-1).$
So there is no longest sequence.
You can replace $(4n+1)!$ with the product $2\prod_{j=1}^{n}(4j+1)$ to get a smaller $M,$ but still it is by far likely not to be the smallest $M$ such that $M,\dots,M+4(n-1)$ have this property.
A: As Tom already explained, you can use the factorials to obtain a sequence of composite non-squares of any length you want.
However, if you only want to go up to a certain bound, your best bet might be to choose the largest $k$ less than the bound such that $k - 1$ is divisible by two consecutive integers.
For example, 9900 is divisible by 99 and 100. Then $4 \times 9900 + 1 =$ $39601 = 199^2$. Therefore, with $k > 9900$, we can be certain that the next $k$ that gives a square for $4k + 1$ is $k = 10100$, which leads to $201^2 = 40401$.
But any of those other $k$ between 9900 and 10100 could give a prime, as far as we know right now. When $k \equiv 1 \pmod 5$ (it ends in 1 or 6 in base 10) and $k > 1$, we can rest assured $4k + 1$ is a multiple of 5, as is, for example, 39605. And we get lucky with 36909 being a multiple of 3.
I give Mathematica the command Select[Range[9890, 10100], PrimeQ[4# + 1] &] and it answers that $k = 9927$ plugged into $4k + 1$ gives a prime, as well as a bunch of other numbers (this works in Wolfram Alpha, too).
Applying Differences[%] (you'll have to be a bit more verbose in Wolfram Alpha, but not necessarily with too much typing) we see the largest difference is 32, but that includes the square 39601 produced by $k = 9900$.
So the longest sequence up to your stated bound of 10000 might indeed be of length 26, but I don't feel like checking $k < 9000$. Not that it would be too difficult in Mathematica or even Wolfram Alpha, it just takes a bit more mental effort than I'm willing to expend on this problem.
