On the number of solutions of the generalized Ramanujan-Nagell equation