working with montogomery factorial