[step:Necessity — derive the $A_p$ inequality by testing $M$ on $w^{1-p'} \mathbb{1}_Q$]
Assume $M: L^p(w) \to L^p(w)$ is bounded with operator norm $\|M\|_{L^p(w) \to L^p(w)} =: A < \infty$.
Fix a cube $Q \subset \mathbb{R}^n$. Define the test function
\begin{align*}
f: \mathbb{R}^n &\to [0, \infty) \\
y &\mapsto w^{1-p'}(y) \, \mathbb{1}_Q(y).
\end{align*}
For every $x \in Q$,
\begin{align*}
M f(x) \ge \frac{1}{|Q|} \int_Q f(y) \, d\mathcal{L}^n(y) = \frac{1}{|Q|} \int_Q w^{1-p'} \, d\mathcal{L}^n = \langle w^{1-p'} \rangle_Q,
\end{align*}
since $Q$ itself is one of the cubes in the supremum defining $M f(x)$.
Therefore
\begin{align*}
\int_Q (M f)^p \, w \, d\mathcal{L}^n \ge \langle w^{1-p'} \rangle_Q^p \, w(Q).
\end{align*}
By the operator-norm bound:
\begin{align*}
\int_Q (M f)^p \, w \, d\mathcal{L}^n \le \int_{\mathbb{R}^n} (M f)^p \, w \, d\mathcal{L}^n \le A^p \int_{\mathbb{R}^n} f^p \, w \, d\mathcal{L}^n = A^p \int_Q w^{p(1-p')} \, w \, d\mathcal{L}^n.
\end{align*}
The exponent simplifies: $p(1-p') + 1 = p - pp' + 1 = p - p \cdot \frac{p}{p-1} + 1$. Using $p p' = p + p'$ (a consequence of $1/p + 1/p' = 1$):
\begin{align*}
p(1-p') + 1 = p - (p + p') + 1 = 1 - p'.
\end{align*}
Hence
\begin{align*}
\int_Q w^{p(1-p') + 1} \, d\mathcal{L}^n = \int_Q w^{1-p'} \, d\mathcal{L}^n = |Q| \langle w^{1-p'} \rangle_Q.
\end{align*}
Combining the two bounds:
\begin{align*}
\langle w^{1-p'} \rangle_Q^p \, w(Q) \le A^p \, |Q| \, \langle w^{1-p'} \rangle_Q.
\end{align*}
If $\langle w^{1-p'} \rangle_Q < \infty$ (which we now verify), divide both sides by $|Q| \langle w^{1-p'} \rangle_Q$ to obtain
\begin{align*}
\langle w \rangle_Q \, \langle w^{1-p'} \rangle_Q^{p-1} \le A^p.
\end{align*}
The finiteness of $\langle w^{1-p'} \rangle_Q$ is a separate point: a priori $w^{1-p'}$ might fail to be locally integrable. To handle this, replace the test function by $f_N := \min(w^{1-p'}, N) \mathbb{1}_Q$ for $N \ge 1$, run the same argument to get
\begin{align*}
\langle w \rangle_Q \, \langle \min(w^{1-p'}, N) \rangle_Q^{p-1} \le A^p,
\end{align*}
and then let $N \to \infty$ via the [Monotone Convergence Theorem](/theorems/???) to deduce both $\langle w^{1-p'} \rangle_Q < \infty$ and the desired inequality.
Taking the supremum over cubes:
\begin{align*}
[w]_{A_p} = \sup_Q \langle w \rangle_Q \langle w^{1-p'} \rangle_Q^{p-1} \le A^p < \infty,
\end{align*}
so $w \in A_p$.
[/step]