By request, I'm spinning my comment out into an answer. For $n$ even, say $n=2k$, subdivide the square into a $k\times k$ grid of squares. I'll show it for $k=5$, because I think it's easier to visualize when everything renders as true squares rather than with $\dots$:
$$\begin{array}{|c|c|c|c|c|}
\hline
\,\,&\,\,&\,\,&\,\,&\,\, \\
\hline
& & & & \\
\hline
& & & & \\
\hline
& & & & \\
\hline
& & & & \\
\hline
\end{array}
$$
Now divide it into the top row of squares, the left column of squares, and everything else:
$$\begin{array}{|c|c c c c|}
\hline
\,\,&\,\,\,\,\mid &\,\,\mid &\,\,\mid& \\
\hline
\underline{\,\,\,}& & & & \\
\underline{\,\,\,}& & & & \\
\underline{\,\,\,}& & & & \\
& & & & \\\hline
\end{array}
$$
(Sorry for the horrible latex hack, but \multicolumn didn't work.) So we have $2k-1$ little squares and one big one, for a total of $2k=n$.
For $n$ odd, split one of the squares into four. (This leaves the "corner case" $n=7$, which I leave as an exercise for the interested reader :)
In problem (a), use Fermat's little theorem, which says (or a rather, a very slightly different version says) that for any prime number $p$, and any integer $n$ that's not divisible by $p$, we have
$$n^{p-1}\equiv 1\bmod p$$
In particular, use $n=2$ and $p=17$. Keep in mind that $2017=(126\times 16)+1$.
In problem (b), note that $30\equiv 61\equiv -1\bmod 31$ (you don't even have to use Fermat's little theorem here).
In problem (c), use Andre's hint above: if $p$ is any prime number other than $3$, then $p^2\equiv 1\bmod 3$ (which you can see is an application of Fermat's little theorem). What does that mean $8p^2$ is congruent to modulo $3$? What does that mean $8p^2+1$ is congruent to modulo $3$? Can a prime number be congruent to that modulo $3$?
Best Answer
The number has to be $15317$. I give in to the temptation of posting my earlier comment as an answer. The number ends in $17$, so we have a starting point, the digit sum is $8$. We now need a digit sum of $9$, and the number appended on the left has to be divisible by $9$. Since $17$ and $9$ are coprime, $17$ x $9$ = $153$ is the smallest such number. Hence the answer to the original question is $15317$.