\newcount\a
\newcount\b
\newcount\c
\newcount\n
\newcount\p
\newcount\q

\def\div#1#2#3{%
  \ifnum#1>#2 %
    \advance#1 by-#2 %
    \div{#1}{#2}{#3}%
  \else%
    \ifnum#1=#2 %
      #3=1%
    \else%
      #3=0%
    \fi%
  \fi%
}

\long\def\isprime#1#2#3{%
  #3=0%
  \ifnum#1>#2 %
    \a=#1 %
    \div{\a}{#2}{\c} %
    \ifnum\c=0 %
      \b=#2 %
      \advance\b by 1 %
      \isprime{#1}{\the\b}{#3}%
    \fi%
  \else%
    #1\par%
    #3=1%
  \fi%
}

\def\listprimes#1#2#3#4{%
  \isprime{\the#1}{2}{#4} %
  \ifnum#4=1 %
    \the#1\par %
    \advance#2 by 1 %
  \fi
  \ifnum#2<#3 %
    \advance#1 by 1 %
    \listprimes{#1}{#2}{#3}{#4} %
  \fi
}

\n=0
\p=2
\listprimes{\p}{\n}{10}{\q}

\end

