Added simple dynamic programming NFromDenom