We study $theta$ dependence of the vacuum energy for the 4d SU(2) pure Yang-Mills theory by lattice numerical simulations. The response of topological excitations to the smearing procedure is investigated in detail, in order to extract topological information from smeared gauge configurations. We determine the first two coefficients in the $theta$ expansion of the vacuum energy, the topological susceptibility $chi$ and the first dimensionless coefficient $b_2$, in the continuum limit. We find consistency of the SU(2) results with the large $N$ scaling. By analytic continuing the number of colors, $N$, to non-integer values, we infer the phase diagram of the vacuum structure of SU(N) gauge theory as a function of $N$ and $theta$. Based on the numerical results, we provide quantitative evidence that 4d SU(2) Yang-Mills theory at $theta = pi$ is gapped with spontaneous breaking of the CP symmetry.