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?

This might be little bit heuristic but what is wrong with the following. Given your $(x,y,z)$ (I am simplifying from $(D_{x},D_{y},D_{z}))$, denote $n(c,x,y,z)=\lceil x/c\rceil\lceil y/c\rceil\lceil z/c\rceil$. $n(c,x,y,z)$ is the number of $c$-sided cubes needed to fill your space. My sense is that i) given $(x,y,z)$, $n(c,x,y,z)$ is decreasing in $c$, ii) $n(c,x,y,z)=1$ for $c\geq\max\{x,y,z\}$, iii) $\lim_{c\rightarrow0^{+}} n(c,x,y,z)=\infty$. Hence the $c$ you are looking for, so that you are as close as possible to $N$, is somewhere in $(0,\max\{x,y,z\})$. an example for $(9,10,11)$ is below.
How to find this $c$? Given the properties of $n(c,x,y,z)$ above, there is $c_{+}$, a largest $c$ such that $n(c,x,y,z)\geq N$ and $c_{-}$, a smallest $c$ such that $n(c,x,y,z)\leq N$. $c_{+}$ is $\sqrt[3]{xyz/N}$ and $c_{-}$ is the value of $c$ where $n(c,x,y,z)$ has 'the next jump'. The $c$ you are after is either $c_{-}$ or $c_{+}$, but to find out which one you have to compare levels of $n(c_{-},x,y,z)$ and $n(c_{+},x,y,z)$.