calculate the optimal factor