The volume of a cylinder is given by cross-sectional area $\times$ length, so $\pi r^2\times \text{length}$.
Working in mm, the original cylinder of sugar has volume $\pi \left(\dfrac{30}{2}\right)^2\times 40mm^3$
Finding the volume of sugar as a number
$\pi \left(\dfrac{30}{2}\right)^2\times 40=\pi\dfrac{30^2}{4}\times40=\pi\times900\times10=9000\pi$.
The cylinder of candy floss has volume $\pi \left(\dfrac{1}{2}\right)^2 x$, so $$\begin{align}\pi \left(\frac{1}{2}\right)^2 x=&9000\pi\\
\Rightarrow\pi\times\frac{1}{4}x=&9000\pi\\
\Rightarrow x=&9000\times4\\
\Rightarrow x=&36000\end{align}$$So $x=36000$mm, or $36$m.
Using algebra to find the length directly
The cylinder of candy floss has volume $\pi \left(\dfrac{1}{2}\right)^2 x$, so $$\begin{align}\pi \left(\frac{1}{2}\right)^2 x&=\pi \left(\frac{30}{2}\right)^2\times 40\\
\Rightarrow 1^2x&=30^2\times40\\
\Rightarrow x&=36000\end{align}$$
So $x=36000$mm, or $36$m.
Using scale factors of enlargement
The ratio of the diameters of the cylinders is 1:30,
so the ratio of the cross-sectional areas is 1:900,
so the height of the thin cylinder will need to 900 times longer than the height of the fat cylinder.
Therefore the height of the thin cylinder is 36m long.