CodeForces 143C Help Farmer
暴力枚举。
枚举最小的那个数字,不会超过$1000$,剩下的两个数字根号的效率枚举一下即可。
#include<bits/stdc++.h> using namespace std; long long n; long long ansMin,ansMax; int main() { scanf("%lld",&n); ansMin=1e18; ansMax=-1; long long p = (long long)pow(1.0*n,1.0/3); p++; for(long long x1=1;x1<=p;x1++) { if(n%x1) continue; long long s = n/x1; for(long long x2=1;x2*x2<=s;x2++) { if(s%x2) continue; long long x3=s/x2; long long A,B,C; A=x1+1; B=x2+2; C=x3+2; ansMin=min(ansMin,A*B*C-n); ansMax=max(ansMax,A*B*C-n); A=x2+1; B=x1+2; C=x3+2; ansMin=min(ansMin,A*B*C-n); ansMax=max(ansMax,A*B*C-n); A=x3+1; B=x2+2; C=x1+2; ansMin=min(ansMin,A*B*C-n); ansMax=max(ansMax,A*B*C-n); } } printf("%lld %lld\n",ansMin,ansMax); return 0; }