\begin{array}{l}\displaystyle a=\frac{(x_1+\cdots+x_n)(y_1+\cdots+y_n)-n(x_1y_1+\cdots+x_ny_n)}{(x_1+\cdots+x_n)^2-n(x_1^2+\cdots+x_n^2)}\\ \\ \displaystyle b=\frac{(x_1+\cdots+x_n)(x_1y_1+\cdots x_ny_n)-(x_1^2+\cdots+x_n^2)(y_1+\cdots+y_n)}{(x_1+\cdots+x_n)^2-n(x_1^2+\cdots+x_n^2)}.\end{array}