In the image there are 2 rectangles: first with a ratio of 1:2.5 and the second with a ratio 0.65:1.

Trying to pack biggest squares possible, in the first example 4 can be packed and in the second 9.
I'm no mathematician so although there's clearly something going on, I can't really put it into a formula.
How do I mathematically determine the minimum number of any-size squares to completely fill a rectangle of a given ratio?