x,y,z都小于等于2000,所以可以枚举所有的长i和宽j,然后通过长i和宽j计算出高度q
然后通过题目条件简单验证p是否合理即可; 如果合理,则可以根据样例解释中的图片想象出里面立方体的摆放方式其实就是它在盒子里面三个维度能够移动的距离+1的乘积。
最后把所有可能求和即可得到答案~
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
const int N = 2e5 + 10;
ll x, y, z, k;
void solve(){
cin >> x >> y >> z >> k;
ll ans = 0;
for(ll i=1; i<=x; i++){
for(ll j=1; j<=y; j++){
ll q = k/(i*j);
if(i*j*q==k && k%(i*j)==0 && q<=z){
//cout << i <<" " << j << " " << k << endl;
ll cnt = (x-i+1)*(y-j+1)*(z-q+1);
ans = max(cnt, ans);
}
}
}
cout << ans << endl;
}
int main() {
int t; cin>>t;
while(t--){
solve();
}
return 0;
}