Solve for $n: \cos\left(\frac\pi4(n^2+2n)\right)=\sin\left(\frac\pi4(n^2+n+1)\right), n\in \mathbb Z$
My Attempt:
$$\cos\left(\frac\pi4(n^2+2n)\right)=\cos\left(\frac\pi2-\frac\pi4(n^2+n+1)\right)\\\implies\frac\pi4(n^2+2n)=2p\pi\pm\left(\frac\pi2-\frac\pi4(n^2+n+1)\right), p\in \mathbb Z$$
With minus sign,
$$\frac\pi4(n^2+2n)=2p\pi-\left(\frac\pi2-\frac\pi4(n^2+n+1)\right)\\\implies n^2+2n=8p-(2-n^2-n-1)\\\implies n=8p-1$$
With plus sign,
$$\frac\pi4(n^2+2n)=2p\pi+\left(\frac\pi2-\frac\pi4(n^2+n+1)\right)\\\implies n^2+2n=8p+(2-n^2-n-1)\\\implies 2n^2+3n=8p+1$$
How to conclude from this?
The answer given is $8p-1$ or $8p-3$.
It follows from $2n^2+3n=8p+1$ that $8p=2n(n+1)+(n-1)$. Since $2\mid n(n+1)$, we have $4\mid 2n(n+1)$, hence $4\mid(n-1)=8p-2n(n+1)$. Let's assume that $n=4k+1$ for some integer $k$, then we have $$8p=4(2k+1)(4k+1)+4k\\\implies 2p=(2k+1)(4k+1)+k.$$ Since $2p$ is even and $(2k+1)(4k+1)$ is odd, we know that $k=2p-(2k+1)(4k+1)$ is odd, hence $k=2m-1$ for some integer $m$, and thus $n=4k+1=8m-3$.
On the other hand, it is a direct calculation to check that all integers of the form $n=8m-3$ for some integer $m$ satisfies $$8\mid(2n^2+3n-1).$$