A complete analytic solution for the time-optimal control problem for nonlinear control systems of the form $\dot x_1=u$, $\dot x_j=x_1^{j-1}$, $j=2,\ldots,n$, is obtained for arbitrary~$n$. In the paper we present the following surprising observation: this nonlinear optimality problem leads to a truncated Hausdorff moment problem, which gives analytic tools for finding the optimal time and optimal controls. Being homogeneous, the mentioned system approximates a certain class of affine systems in the sense of time optimality. Therefore, the obtained results can be used for solving the time-optimal control problem for systems from this class.