Step 1:

$x+y=35$

$y=35-x$

$P=x^2y^5$

$P=x^2(35-x)^5$

$\large\frac{dP}{dx}$$=x^2.5(35-x)^4(-1)+(35-x)^5.2x$

$\quad\;=x^2(35-x)^4[-5x+2(35-x)]$

$\quad\;=x^2(35-x)^4[70-7x]$

Step 2:

When $x$ is slightly < 10 $\large\frac{dP}{dx}=$$(+)(+)(+)=+ve$

When $x$ is slightly > 10 $\large\frac{dP}{dx}=$$(+)(+)(-)=-ve$

$\Rightarrow \large\frac{dP}{dx}$ changes sign from +ve to -ve as $x$ increases through 10.

$\Rightarrow P$ is maximum at $x=10$

From (1) $y=35-10=25$

Hence the required numbers are 10 & 25.