For anyone still reading this thread, or who stumbles across it later, here is the formula in a different language. It's much more concise, and we might even be able to make sense of it.
For R = # of rows, N = # of windows, we have:
WpC= [ ]
cols= int( math.ceil( float( N )/ R ) )
while N> 0:
rows0= int( math.ceil( float( N )/ cols ) )
WpC.append( rows0 )
cols-= 1
N-= rows0
WpC= WpC[ ::-1 ]
It's no Bresenham, but it might do the trick. It generates the table above. The result is a list of number of windows per column (WpC). The same formula would apply for determining windows per row, I imagine. If you want squares, just pick R = floor or ceil of sqrt( N ).
The language it's in is Python. The last statement reverses the list. Lately I learned that the MDI Window control in Linux doesn't offer 'Tile' capabilities, horizontal, vertical, or otherwise. It should.