# 492.Construct the Rectangle

**492.Construct the Rectangle**

难度:Easy

> 作为一位web开发者， 懂得怎样去规划一个页面的尺寸是很重要的。 现给定一个具体的矩形页面面积，你的任务是设计一个长度为 L 和宽度为 W 且满足以下要求的矩形的页面。要求：

1. 你设计的矩形页面必须等于给定的目标面积。
2. 宽度 W 不应大于长度 L，换言之，要求 L >= W 。
3. 长度 L 和宽度 W 之间的差距应当尽可能小。 你需要按顺序输出你设计的页面的长度 L 和宽度 W。

```
示例：

输入: 4
输出: [2, 2]
解释: 目标面积是 4， 所有可能的构造方案有 [1,4], [2,2], [4,1]。
但是根据要求2，[1,4] 不符合要求; 根据要求3，[2,2] 比 [4,1] 更能符合要求. 所以输出长度 L 为 2， 宽度 W 为 2。
说明:

给定的面积不大于 10,000,000 且为正整数。
你设计的页面的长度和宽度必须都是正整数。
```

从平方根开始往下走，遇到整除的就是了。

```
class Solution {
public:
    vector<int> constructRectangle(int area) {
        int s=sqrt(area);
       // cout<<"s  "<<s<<endl;
        int q=0;
        for(int i=s;i>=1;--i)
        {
            if(area%i ==0) {q=i; break;}
        }
        if(!q)q=1;
        vector<int >res(2);
        res[1]=q;
        res[0]=area/q;
        return res;
    }
};
```

> 执行用时 :8ms, 在所有 C++ 提交中击败了69.50%的用户\
> 内存消耗 :8.2 MB, 在所有 C++ 提交中击败了86.64%的用户


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dfine.gitbook.io/leetcode/492.construct_the_rectangle.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
