\(\left\{{}\begin{matrix}a+b=a^2+b^2\\a^3+b^3=a^2+b^2\end{matrix}\right.\) \(\Rightarrow a+b+a^3+b^3=2a^2+2b^2\)
\(\Leftrightarrow a\left(a^2-2a+1\right)+b\left(b^2-2b+1\right)=0\)
\(\Leftrightarrow a\left(a-1\right)^2+b\left(b-1\right)^2=0\)
\(\Leftrightarrow a=b=1\)
\(\Rightarrow P=2\)