Solution (source code)

= Solution

For $Q=p$ and $P=\lambda q$,
$$
\{Q,P\}_{q,p}=-\lambda.
$$
The map is therefore canonical only for
$$
\boxed{\lambda=-1}.
$$
Then $Q=p$ and $P=-q$. The <type-one generating function for a canonical transformation>
$$
\boxed{\Phi(q,Q)=qQ}
$$
gives
$$
p=\Phi_q=Q,
\qquad
P=-\Phi_Q=-q,
$$
as required.