タイトル通りです.
\usepackage[ドライバ]{xcolor}
% =============================================
\makeatletter
\def\Prime#1{\bgroup\def\numcolor{\textcolor{red}}%
\@tempcnta#1\@tempcntb\tw@%
\ifnum\@tempcnta=1
\let\numcolor\relax%
\else
\@whilenum\@tempcntb<\@tempcnta\do{%
\divide\@tempcnta\@tempcntb\multiply\@tempcnta\@tempcntb\relax
\ifnum\@tempcnta=#1\let\numcolor\relax\fi
\@tempcnta#1\advance\@tempcntb\@ne\relax
}
\fi\numcolor{#1}\egroup}
\makeatother
\Prime{5}
\Prime{334}
結果
5 334
自分もまだ勉強段階です.