Hi, if we given n unit squares and asked to place inside a rectangle such that the difference between the lenght and breadth of the rectangle is minimum..how can we place them?

E.g if we given 20 such unit squares we can place them in a 5X4 rectangle. For 150 , its 10X15, for 100 its 10X10 while for 17 its 1X17 .. My initial thoughts were factoringNand taking the square factors but it doesn't seem to work..Thanks.