CountFactors solution