Here is a proposal that works for arbitrary integers. The color is unique and set by \definecolor{mycol}{RGB}{\myr,100,\myb}. If you want different colors, you need to adjust this bit of code.
\documentclass[tikz,border=3mm]{standalone}
\tikzset{pics/colored grid/.style={code={
\pgfmathtruncatemacro{\mymod}{0.5+sqrt(#1)}
\pgfmathtruncatemacro{\mymmod}{\mymod+ifthenelse(#1>\mymod*\mymod,1,0)}
\draw (0,0) grid (\mymod-1,1-\mymmod);
\foreach \XX in {1,...,#1}
{\pgfmathtruncatemacro{\myr}{mod(\XX-1,\mymod)*255/(\mymod-1)}
\pgfmathtruncatemacro{\myb}{int((\XX-1)/\mymod)*255/(\mymmod-1)}
\definecolor{mycol}{RGB}{\myr,100,\myb}
\path ({mod(\XX-1,\mymod)},{-int((\XX-1)/\mymod)})
node[circle,draw,text width={width("11")},align=center,
fill=mycol]{\XX};}
}}}
\begin{document}
\begin{tikzpicture}
\path (0,0) pic{colored grid=24} (6,0) pic{colored grid=25}
(0,-6) pic{colored grid=33};
\end{tikzpicture}
\end{document}
