#P1731. Birthday Cake

    ID: 15016 Type: Default 1000ms 256MiB

Birthday Cake

Birthday Cake

On July 17, it is Mr. W's birthday. ACM-THU is preparing a birthday cake with a volume of (N\pi) and consisting of (M) cylindrical layers. The cake is built such that the (i)th layer from the bottom ((1 \le i \le M)) is a cylinder with radius (R_i) and height (H_i). For (i < M) it is required that (R_i > R_{i+1}) and (H_i > H_{i+1}).

When the cake is assembled the exterior is iced (except the bottom face of the lowest layer). Its total exposed surface area is denoted by (Q). With a little algebra it can be shown that

[ Q = \left(\sum_{i=1}^{M}2R_iH_i\right)\pi + R_1^2\pi, ]

so if we define

[ S = \frac{Q}{\pi} = R_1^2 + \sum_{i=1}^{M}2R_iH_i, ]

your task is: Given positive integers (N) and (M), choose positive integers (R_i) and (H_i) satisfying

[ \sum_{i=1}^{M}R_i^2H_i = N \quad \text{and} \quad R_1 > R_2 > \cdots > R_M, ; H_1 > H_2 > \cdots > H_M, ]

so that (S) is minimized. (Note that aside from (Q), all the given data are positive integers.)

If no cake configuration meets the conditions, output 0.

inputFormat

The input consists of a single line containing two space‐separated positive integers (N) and (M).

outputFormat

Output a single integer — the minimum possible value of (S) for a cake configuration that satisfies the conditions. If no valid configuration exists, output 0.

sample

100 1
65