Prime factorisation function