#include<iostream>
using namespace std;
int main (){
long long int L,a=1,i,max=0,b;
while(cin>>L&&L%2==0){
for(i=1;i<=L/2;i++){
b=(L/2-a)*a;
a++;
if(b>max){
max=b;
}
}
cout<<max<<endl;
a=1;
}
return 0;
}
與正確輸出不相符(line:17)
您的答案為: 6081156
正確答案為: 3705625
cout<<max<<endl;
a=1, max=0;
}
return 0;
}
記得初始化
不要用窮舉法, 這一題很明顯兩邊長越接近, 面積會越大,
也就是先把數入的數字 n/2 (因為一定偶數, 不用擔心)
結果如果是奇數, 就是 (n/2)/2+1 * (n/2)/2;
如果是偶數, 就是 (n/4)^2