first version of calculating number of factories