Solution (source code)

= Solution

Condition on the <claim count>. The empty <random sum of independent claims> is zero, and independence gives $\mathbb E[e^{tS}\mid N=n]=M_X(t)^n$. Therefore the <random-sum transform identity> is
$$
\boxed{M_S(t)=\sum_{n=0}^{\infty}\mathbb P(N=n)M_X(t)^n=G_N(M_X(t)),}
$$
wherever the composition is finite. This follows directly from the <law of total expectation>, rather than replacing the random count by its mean.

Put $q=1-p$. For the specified <negative binomial distribution>, the <negative binomial series> gives $G_N(z)=[p/(1-qz)]^k$. A rate-$\lambda$ <exponential distribution> has <moment-generating function> $M_X(t)=\lambda/(\lambda-t)$. Hence
$$
M_S(t)=\left(\frac{p(\lambda-t)}{p\lambda-t}\right)^k
=\left(p+q\frac{p\lambda}{p\lambda-t}\right)^k,\qquad t<p\lambda.
$$
The last expression is exactly the <moment-generating function> of a <compound binomial distribution> with independent count and severities
$$
\boxed{\widetilde N\sim\operatorname{Binomial}(k,1-p),\qquad\widetilde X_j\sim\operatorname{Exp}(p\lambda).}
$$
The <moment-generating function> exists in a neighborhood of zero, so its uniqueness identifies the distributions. In particular, the new <claim sizes> have mean $1/(p\lambda)$, not $1/\lambda$, and both aggregate distributions have an atom $p^k$ at zero. This is the <negative-binomial sum of exponential claims> representation with the severity rate explicitly retained.

Conditional on $N=n\ge1$, the aggregate has <Erlang distribution> with density $\lambda^n s^{n-1}e^{-\lambda s}/(n-1)!$ on $s>0$. Repeated <integration by parts> of its tail gives
$$
\mathbb P(S>x\mid N=n)=e^{-\lambda x}\sum_{j=0}^{n-1}\frac{(\lambda x)^j}{j!}.
$$
Indeed, after substituting $v=\lambda s$, the integral $\int_{\lambda x}^{\infty}e^{-v}v^{n-1}\,dv/(n-1)!$ reduces recursively to the corresponding integral with exponent $n-2$, terminating at $e^{-\lambda x}$. Applying the <law of total probability> yields the original infinite <mixture distribution> tail
$$
\mathbb P(S>x)=\sum_{n=1}^{\infty}p_n e^{-\lambda x}\sum_{j=0}^{n-1}\frac{(\lambda x)^j}{j!},\qquad x>0.
$$
Applying the same argument to the <compound binomial distribution> gives instead the <finite Erlang-mixture tail for a negative-binomial exponential aggregate>:
$$
\boxed{\mathbb P(\widetilde S>x)=\sum_{n=1}^{k}\binom{k}{n}q^n p^{k-n}e^{-p\lambda x}\sum_{j=0}^{n-1}\frac{(p\lambda x)^j}{j!}.}
$$
The two tails are equal. \b[The binomial representation replaces an infinite sum by a finite exact calculation], eliminating the need to choose a claim-count truncation and control its omitted tail. The inner sums can be evaluated recursively, using $a_{j+1}=a_j(p\lambda x)/(j+1)$ for their exponential-weighted terms.