blob: 34c771501e1fa064cb84b736d91ec8499c875ef7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
\newif\ifprime \newif\ifunknown
\newcount\n \newcount\p
\newcount\d \newcount\a
\def \primes#1{2,~3\n=#1 \advance \n by-2 \p=5
\loop \ifnum \n>0 \printifprime \advance \p by2 \repeat}
\def \printp{, \ifnum \n=1 and~\fi
\number \p \advance \n by -1 }
\def \printifprime{\testprimality \ifprime\printp\fi}
\def \testprimality{{\d=3 \global \primetrue
\loop \trialdivision \ifunknown \advance \d by2 \repeat}}
\def \trialdivision{\a=\p \divide \a by\d
\ifnum \a>\d \unknowntrue \else \unknownfalse \fi
\multiply \a by\d \ifnum \a=\p \global \primefalse \unknownfalse \fi}
\endinput
|