Consider a quadrature rule of the form $$ Q(f) = \sum_{i=0}^{n} A_{i}f(x_{i})$$ to approximate the integral $$\int_{a}^{b}w(x)f(x)dx,$$ where $w:[a,b] \to \mathbb{R}$ is a positive function. Prove that $Q(f)$ is exact for all polynomials $f$ of degree less than or equal to $n$ if and only if $$A_{i}=\int_{a}^{b}w(x)\prod_{\substack{j =0\\j \neq i}}^{n}\frac{x-x_{j}}{x_{i}-x_{j}}dx.$$
I can prove the backward implication, that if $A_{i}$ is as stated, then $Q(f)$ is exact for all polynomials $f$ of degree less than or equal to $n$, but I am not sure how to prove that if $Q(f)$ is exact, then $A_{i}$ must be as stated.