For any polynomial $P\in {\mathsf C} [X_1,X_2,\ldots,X_n]$, we describe a $\mathsf C$-vector space $F(P)$ of solutions of a linear system of equations coming from some algebraic partial differential equations such that the dimension of $F(P)$ is the number of irreducible factors of $P$. Moreover, the knowledge of $F(P)$ gives a complete factorization of the polynomial $P$ by taking gcd's. This generalizes previous results by Ruppert and Gao in the case $n=2$.