JuniorMath
Construct the Rectangle
A web developer needs to know how to design a web page's size. Given a specific rectangular web page's area, design a rectangular web page whose length L and width W satisfy the following requirements:
- The area of the rectangular web page you designed must equal the given target
area. - The width
Wshould not be larger than the lengthL, which meansL >= W. - The difference between length
Land widthWshould be as small as possible.
Return an array [L, W] where L and W are the length and width of the web page you designed, in sequence.
Example 1
Input
area = 4Output
[2,2]The target area is 4, and among the valid dimensions with L >= W, [2, 2] has the smallest difference between length and width.
Example 2
Input
area = 37Output
[37,1]Since 37 is prime, the only valid dimensions are L = 37 and W = 1.
Constraints
- 1 <= area <= 10^7