Artifact 9c730bac0778f4f4c89d6d3fae53b9777110fdc4
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <cstring>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;
class CubePacking { public:
int getMinimumVolume(int Ns, int Nb, int L)
{
int m = L*L*L*Nb + Ns;
int M = L*L*L*Nb + Ns + L*L;
for(int c=m; c<=M; ++c) // <M should be fine, but just in case...
{
for(int p=1; p*p*p<=c; ++p) if( c%p == 0 )
for(int q=p; p*q*q<=c; ++q) if( c/p%q == 0 )
{
int r = c/p/q;
int nL = (p/L)*(q/L)*(r/L);
if( Nb <= nL )
return c;
}
}
assert(false);
return -1;
}
};
// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
{ ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
{ os << "{ ";
for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const int& Expected, const int& Received) {
bool ok = (Expected == Received);
if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl;
cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END verify_case(_, CubePacking().getMinimumVolume(Ns, Nb, L));}
int main(){
CASE(0)
int Ns = 2;
int Nb = 2;
int L = 2;
int _ = 20;
END
CASE(1)
int Ns = 19;
int Nb = 1;
int L = 2;
int _ = 27;
END
CASE(2)
int Ns = 51;
int Nb = 7;
int L = 5;
int _ = 950;
END
CASE(3)
int Ns = 12345;
int Nb = 987;
int L = 10;
int _ = 999400;
END
CASE(4)
int Ns = 1000000000;
int Nb = 1000000;
int L = 10;
int _ = -1;
END
CASE(5)
int Ns = 1;
int Nb = 1;
int L = 1;
int _ = 2;
END
CASE(5)
int Ns = 1;
int Nb = 1;
int L = 2;
int _ = 12;
END
}
// END CUT HERE