Solution (source code)

= Solution

The <prime ideal factorization> of $pB$ is
$$
pB=\prod_{q\mid p}q^{e_{q/p}},
$$
which defines the <ramification index of a prime ideal> $e_{q/p}=v_q(pB)$. The <residue-field degree> is
$$
f_{q/p}=[B/q:R/p].
$$
Localizing at $p$ makes $B_p$ a free $R_p$-module of rank $[L:K]$, so $B/pB$ has dimension $[L:K]$ over the <residue field> $R/p$. The <Chinese remainder theorem> and the filtration by powers of each $q$ decompose this vector space into $e_{q/p}$ successive quotients isomorphic to $B/q$, each of dimension $f_{q/p}$. Therefore the <fundamental identity for prime decomposition> gives
$$
\boxed{[L:K]=\sum_{q\mid p}e_{q/p}f_{q/p}.}
$$