Let the initial number of students be \(n\), total sum \(S=50n\). Let minimum stipend be \(m\) and maximum be \(M\) with \(M-m=45\).
Excluding these two, the new average is \(49\) on \(n-2\) students:
\[
50n - (M+m) = 49(n-2) \quad\Rightarrow\quad M+m = n+98.
\]
Solve
\[
M=\frac{(M+m)+(M-m)}{2}=\frac{(n+98)+45}{2}=\frac{n+143}{2},\qquad
m=\frac{(n+98)-45}{2}=\frac{n+53}{2}.
\]
Given \(m\in[42,47]\):
\[
42 \le \frac{n+53}{2} \le 47
\ \Longrightarrow\
31 \le n \le 41.
\]
Now \(n\) is a two-digit \emph{prime} whose both digits are prime (digits from \(\{2,3,5,7\}\)). The only such prime in \([31,41]\) is \(\boxed{37}\).
(Then \(m=(37+53)/2=45\) which lies in \([42,47]\), and \(M=(37+143)/2=90\); removing \(\{45,90\}\) changes the average from \(50\) to \(49\) as required.)
\[
\boxed{37}
\]