/* This is an enumeration search of the radius and height, however, pruning is required */# include <iostream> # include <cmath> # include <cstdio> # include <algorithm> using namespace std; int n, m, minv [21], mins [21], best; void dfs (int M, int v, int s, int r, int h) {int I, j, hmax; if (M = 0) {if (v = n & s <best) best = s; return ;} if (v + minv [M]> n | s + mins [M]> = best | 2 * (n-v)/r + s> = best) return; // trim the current volume and the minimum volume of the remaining M layer is greater than n // The lateral area and the Minimum side area of the remaining M layer are greater than or equal to the best/* The side area of the remaining M layer is lefts = 2 * (r [k] * h [k] +... + r [m] * h [m]), k = (M + 1 ,.., m) lefts> 2 * (n-v)/r; lefts = best-s; */for (I = R-1; I> = M; I --) {if (M = m) s = I * I; hmax = min (n-v)/(I * I), h-1); for (j = hmax; j> = M; j --) dfs (M-1, v + I * j, s + 2 * I * j, I, j );}} int main (int argc, char * argv []) {int I, rmax, hmax; minv [0] = 0; mins [0] = 0; for (I = 1; I <21; I ++) mins [I] = mins [I-1] + 2 * I, minv [I] = minv [I-1] + I * I; // array mins, minv records the minimum area and volume of the layer, obtained when I is equal to; while (cin> n> m) {rmax = sqrt (1.0 * n) + 1; hmax = n/(m * m) + 1; best = 1000000; dfs (m, rmax, hmax ); if (best = 1000000) best = 0; cout <best <endl;} return 0 ;}