As part of a computer program I'm writing, I have a rectangular, three-dimensional volume of dimensions ($D_x$, $D_y$, $D_z$) which is aligned with all major axis.
I want to cover the contents of this space into cube-shaped sections whose sides are all $C$ units long. Here's an illustration:
Note that some cubes may stick out on one side of the volume, if the length of the side is not equal to a multiple of $C$. Since I want to cover the volume with cubes, the number of cubes I need in each side of the volume is $\left\lceil \frac{D}{C} \right\rceil$, where $D$ is any side of the volume.
As an additional constraint, I'd like to use as close to $N$ cubes as possible to cover this volume. This means I am varying the value of $C$, fill the volume with cubes of that size, and end up with a total cube count, which I am trying to optimise to be as close to $N$ as possible.
The dimensions of the volume as well as the sides of the cubes are real values (floating point). $N$ is a positive integer.
Is there a means of choosing a value of $C$ such that the resulting number of cubes necessary to cover the volume is as close to $N$ as possible?

