Artifact 34827d4e4ac8d217cd082419de6ccac314429340
#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 CorrectMultiplication { public:
long long getMinimum(int a, int b, int c)
{
return solve(a,b,c);
}
LL solve(LL a, LL b, LL c)
{
if( a > b )
swap(a,b);
LL vv = (1LL<<62);
for(LL A=1; A*A <= (a+b+c)*2; ++A)
vv = min(vv, best_of(A,a,b,c));
return vv;
}
LL best_of(LL A, LL a, LL b, LL c)
{
LL Bl = 1;
LL Br = a+b+c;
while( Bl+3 < Br )
{
LL Bc1 = (Bl*2+Br*1) / 3;
LL Bc2 = (Bl*1+Br*2) / 3;
LL cc1 = abs(A-a)+abs(Bc1-b)+abs(A*Bc1-c);
LL cc2 = abs(A-a)+abs(Bc2-b)+abs(A*Bc2-c);
if(cc1 < cc2)
Br = Bc2;
else
Bl = Bc1;
}
LL vv = (1LL<<62);
for(LL B=Bl; B<=Br; ++B)
vv = min(vv, abs(A-a)+abs(B-b)+abs(A*B-c));
return vv;
}
};
// 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 long long& Expected, const long long& 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(_, CorrectMultiplication().getMinimum(a, b, c));}
int main(){
CASE(0)
int a = 19;
int b = 28;
int c = 522;
long long _ = 2LL;
END
CASE(1)
int a = 10;
int b = 30;
int c = 500;
long long _ = 11LL;
END
CASE(2)
int a = 11111;
int b = 11111;
int c = 123454321;
long long _ = 0LL;
END
CASE(3)
int a = 1000;
int b = 100;
int c = 10;
long long _ = 1089LL;
END
CASE(4)
int a = 399;
int b = 522;
int c = 199999;
long long _ = 24LL;
END
CASE(5)
int a = 1000000000;
int b = 1000000000;
int c = 1000000000;
long long _ = -1LL;
END
/*
CASE(6)
int a = ;
int b = ;
int c = ;
long long _ = LL;
END
*/
}
// END CUT HERE