题解:P12868 [蓝桥杯 2025 国 Python A] 最大周长

· · 题解

我们可以枚举长方形的长和宽,检查是否乘积是否是 2025 这个数字,用公式 C=2(a+b) 计算周长,取最大值即为答案。

上代码。

#include <bits/stdc++.h>
using namespace std;
int mx=-1;
signed main(){
    for(int i=1;i<=2025;i++){
        for(int j=1;j<=2025;j++){
            if(i*j==2025){
                mx=max(mx,(i+j)*2);
            }
        }
    }cout<<mx;
    return 0;
}