I think you need to contemplate displaying your table in landscape mode, especially if you want to avoid having to resort to minuscule font sizes. In the code below, I use \allowbreak
directives to introduce line breaks in some of the columns. I would also like to recommend (i) not using any vertical lines in the table and (ii) using the line-drawing macros of the booktabs
package instead of \hline
and \cline
.

\documentclass[a4paper]{article} % specify page size
\usepackage[margin=1in]{geometry} % specify text block size
\usepackage{rotating,tabularx,amssymb,ragged2e,booktabs}
\newcolumntype{C}{>{\Centering\arraybackslash}X}
\newcommand\swb{{\scriptstyle\Box}} % "small white box"
\begin{document}
\begin{sidewaystable}
\setlength\tabcolsep{2pt} % default value: 6pt
\begin{tabularx}{\textwidth}{@{}*{10}{C}@{}}
\toprule
$\delta_m$ & $2 \neq \swb$ & \multicolumn{4}{c}{$5 \cdot 29 \neq \swb$} & \multicolumn{4}{c}{$13 \cdot 1789 \neq \swb$} \\
\cmidrule(lr){3-6} \cmidrule(l){7-10}
& & $5=\swb$ & $29\neq\swb$ & $5\neq\swb$ & $29=\swb$ & $13=\swb$ & $1789\neq\swb$ & $13\neq\swb$ & $1789=\swb$ \\
\midrule
Primes that satisfy the condition $\delta_m \neq \swb$ &
$q\equiv\pm3\pmod8$ &
$q\equiv\pm1\pmod5$ &
$q\equiv 2,3,8,10,\allowbreak11,12,14,15,\allowbreak17,18,19,21,\allowbreak26,27\pmod{29}$ &
$q\equiv\pm2\pmod5$ &
$q\equiv 1,4,5,6,\allowbreak7,9,13,16,20,\allowbreak22,23,24,25,\allowbreak28\pmod{29}$ &
$q\equiv 1,3,4,9,\allowbreak10,12\pmod{13}$ &
$q\equiv A\pmod{1789}$ &
$q\equiv2,5,6,7,\allowbreak8,11\pmod{13}$ &
$q\equiv B\pmod{1789}$ \\
\midrule
Period of $w_n$ & $24$ & $30$ & $102$ & $30$ & $102$ & $30$ & $2670$ & $30$ & $2670$ \\
\bottomrule
\end{tabularx}
\end{sidewaystable}
\end{document}