The first step is to figure out how many rows $R$ and columns $C$ you want. If you want N squares, you need $R*C\ge N$. If you are given the dimensions of the rectangle, say w is the ratio of the width $W$ to the height $H$(presumed $\ge 1$). Then you probably want $C/R$ to be about this, so $R^2w \ge N$ Now you can round up to get $R$ and divide and round up to get $C$.
To get the coordinates of each square of side $s$, there is some space $t$ between the squares. So $Cs+(C-1)t\le W$ and $Rs+(R-1)t\le H$ and you lay them out starting at (0,0) if that is top left in increments of $s+t$
Added: for 34 tiles in 600 wide by 200 high, you can either have a 4x10 or 3x12 layout (with some blanks like you showed in the original question). If we take the 4x10 option, then you can have, for example, the tiles 45 high, which uses up 180 of the 200. This leaves 20 units to divide by 3, so the gaps would be 6. But going the other way, 10 tiles would use 450, leaving 50 to divide by 9, so the gaps could only be 5. Then the top left tile is at (0,0), the next one down is at (50,0), the next at (100,0) and the last at (150,0) with its bottom at 195. In width they go 0, 50, 100, 150,...450 with the right edge at 495. Is that what you were looking for?