Correctly calculate the number of factors