This letter considers cooperative spectrum sensing (CSS) in a heterogeneous cognitive radio network, where K non-identical cognitive users (CUs) and a fusion center (FC) collaboratively detect the primary user's signal using the N-out-of-K rule in the presence of erroneous control channels. We formulate a generalized optimal fusion problem (GOFP) to optimize the N-out-of-K rule for the Bayesian test and then solve the GOFP to obtain the optimal value of N. It follows that existing results on the optimal value of N in the N-out-of-K rule are special cases of the proposed solution. We then propose a framework to obtain the smallest number of CUs required in CSS while satisfying a target error bound at the FC. Numerical results are presented using the energy detector as an example. © 1994-2012 IEEE.