[Tex/LaTex] Page Numbering: Prime Numbers

page-numbering

I'm writing a project and would like each of my pages be numbered in terms of primes. That is, rather than 1,2,3,…, I'd like 2,3,5,…. I managed to find the following three pages:

However, not being tech savvy, I have no idea how to use this. Just in case it makes a difference, I already know I need 49 pages and so I only need the first 49 primes (in case this let you define a set of some sort that it can utilise). Is there a way to do this without having to reset the counter on each page (which would require knowing where each page begins)?

Best Answer

prime pages 1 prime pages 2 prime pages 3 prime pages 4 prime pages 5

\documentclass{article}
\newcommand{\nthprime}[1]{%
  \ifcase #1\relax
  \or 2\or 3\or 5\or 7\or 11\or 13\or 17\or 19\or 23\or 29\or 31\or
  37\or 41\or 43\or 47\or 53\or 59\or 61\or 67\or 71\or 73\or 79\or 
  83\or 89\or 97\or 101\or 103\or 107\or 109\or 113\or 127\or 131\or 
  137\or 139\or 149\or 151\or 157\or 163\or 167\or 173\or 179\or 181\or 
  191\or 193\or 197\or 199\or 211\or 223\or 227\or 229\or 233\or 239\or
  241\or 251\else 997\fi }
\renewcommand{\thepage}{\nthprime{\value{page}}}
\usepackage[paperheight=6cm]{geometry}
\usepackage{lipsum}
\begin{document}
\tableofcontents
\newcount\cnta
\cnta1
\loop
\section{a section}
\lipsum[\cnta-\numexpr\cnta+3\relax]
\advance\cnta 4
\ifnum\cnta < 50
\repeat
\end{document}