\section{Introduction}\label{sec:intro} \subsection{Results} For a natural number $N$ let $b(N)$ be the length of its binary expansion (so $b(0)=0$ and $b(N)=\floor{\log_2N}+1$ for $N\ge1$), and for a natural number $C$ put \begin{equation}\label{eq:TC} T_C(N)=\Bigl\lfloor C\cdot 2^{\,C\,b(N)/\sqrt{\log_2(b(N)+2)}}\Bigr\rfloor . \end{equation} Numbers are written in binary, least significant bit first, and $0$ is the empty word. ``Machine'' means a deterministic multi-stack Turing machine with finite stack alphabets, in the sense of Mathlib's \lean{TM2} model with its timed halting relation \lean{TM2OutputsInTime}; the step count includes everything the machine does. Section~\ref{sec:engine} recalls the model. \begin{mainsum}[Exact prime sum] There are a machine $M$ and a constant $C$ such that for every $N\in\N$, on input $N$ the machine $M$ halts within $T_C(N)$ steps with output $S(N)=\sum_{p\le N,\ p\ \mathrm{prime}}p$. \end{mainsum} \begin{maincount}[Exact prime counting] There are a machine $M$ and a constant $C$ such that for every $N\in\N$, on input $N$ the machine $M$ halts within $T_C(N)$ steps with output $\pi(N)$. \end{maincount} \begin{mainfind}[Deterministic prime finding] There are a machine $M$ and a constant $C$ such that for every $N\in\N$, on input $N$ the machine $M$ halts within $T_C(N)$ steps and outputs a prime $p$ with $N
0$, and conjectures
\cite[Conjecture~1.1]{TCH} that in the same time one can decide whether
such an interval contains a prime, which would give prime finding in that
time. Corollary~\ref{cor:interval} decides this in time $N^{o(1)}$ for
every interval in $[N,2N]$, with no restriction on its length. In a
different direction, primes can be constructed
\emph{pseudodeterministically}, by a randomized algorithm that outputs the
same prime with high probability: in subexponential time for infinitely
many lengths \cite{OS}, and in polynomial time for infinitely many lengths
\cite{CLORS}. Theorem~C is deterministic and holds for every $N$.
\emph{Counting engines.} The Exponential Time Hypothesis \cite{IP} asserts
that 3-SAT on $n$ variables requires time $2^{\delta n}$ for some
$\delta>0$. In October 2026 two deterministic algorithms for \#3-SAT in
time $2^{o(n)}$ were announced, with Lean formalizations \cite{O,A}; the
one of \cite{A} counts satisfying assignments of a $k$-CNF in time
$2^{O(n\log\log n/\sqrt{\log n})}$ by evaluating tensor networks, and it is
the one we use. Consequences for number-theoretic problems followed
quickly, among them deterministic factoring in time $N^{o(1)}$ \cite{RR}
and, closest to the present paper, Tulsyan's computation of the parity of
$\pi(N)$ in time $N^{o(1)}$ \cite{T1}, whose counting-package interface we
use. The notes accompanying \cite{T1} record exact $\pi(N)$ and
deterministic prime finding as out of reach of that approach without a
further, analytic component, and \cite{T2} studies the limits of the
engines. Theorems~A--C supply such a component. Like all these results,
they are reductions to the engine of \cite{A} and inherit its running time.
\emph{Analytic tools.} The evaluation $\mu(d)=\sum_{(x,d)=1}\e(x/d)$ is
Ramanujan's \cite{R}, and the geometric convergence of the trapezoidal rule
for periodic analytic functions is classical \cite{TW}. We use both in an
elementary form with explicit constants: the first removes any need to
factor, and the second turns the logarithm, its reciprocal and the phases
into short combinations of rational functions of constant degree, which is
what the counting engine can evaluate (Remark~\ref{rem:separation}).
\subsection{What kind of result this is}
Theorems~A--C are reductions. They transform prime summation, prime
counting and prime finding into counting problems of the kind solved by the
algorithm of \cite{A}; we do not propose a new counting engine, and the
running time is the one that algorithm provides. The results are purely
asymptotic and of theoretical interest only. The constants are very large
(the reduction alone introduces a network constant $2^{22}\cdot132$ and a
padding factor $2049$), so the bound $T_C(N)$ falls below the classical
$N^{1/2}$ only for very large $N$; we do not extract $C$ and give no
estimate of that range.
\subsection{Overview of the proof}\label{sec:overview}
The engine of \cite{A}, in the packaged form of \cite{T1} extended here to
polynomially many adaptive queries (Section~\ref{sec:engine}), counts the
solutions of a system of arithmetic constraints in time
$2^{O(n/\sqrt{\log n})}$, provided the system has only $O(n)$ shared bits.
This linear bound is the whole difficulty. The number of primes up to $N$
is the number of solutions of ``$p\le N$ and $p$ is prime'', but every known
encoding of primality by arithmetic constraints uses far more than $O(b)$
auxiliary bits, and evaluating $\log n$ inside the system by the standard
circuits does not give a linear bound either. We avoid both.
\emph{Step~1: a formula without factorization} (Section~\ref{sec:formula}).
For $n\ge2$ one has $\mathbf 1_{\mathrm{prime}}(n)=-\mu(n)\Lambda(n)/\log n$.
Writing $\Lambda=\mu*\log$ and expressing both M\"obius values by
Ramanujan's evaluation $\mu(d)=\sum_{(x,d)=1}\e(x/d)$ gives
\[
S(N)=-\sum_{2\le n\le N}\ \sum_{\substack{0\le x