Simple quadratic problem

any speed improvement will be welcomed