Solution to the CountSemiprimes problem