0bad7aa887 2013-12-14 kinaba: #include <iostream> 0bad7aa887 2013-12-14 kinaba: #include <sstream> 0bad7aa887 2013-12-14 kinaba: #include <iomanip> 0bad7aa887 2013-12-14 kinaba: #include <vector> 0bad7aa887 2013-12-14 kinaba: #include <string> 0bad7aa887 2013-12-14 kinaba: #include <map> 0bad7aa887 2013-12-14 kinaba: #include <set> 0bad7aa887 2013-12-14 kinaba: #include <algorithm> 0bad7aa887 2013-12-14 kinaba: #include <numeric> 0bad7aa887 2013-12-14 kinaba: #include <iterator> 0bad7aa887 2013-12-14 kinaba: #include <functional> 0bad7aa887 2013-12-14 kinaba: #include <complex> 0bad7aa887 2013-12-14 kinaba: #include <queue> 0bad7aa887 2013-12-14 kinaba: #include <stack> 0bad7aa887 2013-12-14 kinaba: #include <cmath> 0bad7aa887 2013-12-14 kinaba: #include <cassert> 0bad7aa887 2013-12-14 kinaba: #include <tuple> 0bad7aa887 2013-12-14 kinaba: using namespace std; 0bad7aa887 2013-12-14 kinaba: typedef long long LL; 0bad7aa887 2013-12-14 kinaba: typedef complex<double> CMP; 0bad7aa887 2013-12-14 kinaba: 0bad7aa887 2013-12-14 kinaba: class BigFatInteger { public: 0bad7aa887 2013-12-14 kinaba: int minOperations(int A, int B) 0bad7aa887 2013-12-14 kinaba: { 0bad7aa887 2013-12-14 kinaba: vector<int> s; 0bad7aa887 2013-12-14 kinaba: for(int p=2; p*p<=A; ++p) 0bad7aa887 2013-12-14 kinaba: { 0bad7aa887 2013-12-14 kinaba: int c = 0; 0bad7aa887 2013-12-14 kinaba: while(A%p==0) A/=p, ++c; 0bad7aa887 2013-12-14 kinaba: if(c) s.push_back(c*B); 0bad7aa887 2013-12-14 kinaba: } 0bad7aa887 2013-12-14 kinaba: if(A>1) 0bad7aa887 2013-12-14 kinaba: s.push_back(1*B); 0bad7aa887 2013-12-14 kinaba: 0bad7aa887 2013-12-14 kinaba: int cnt = s.size(); 0bad7aa887 2013-12-14 kinaba: vector<int> cur(s.size(), 1); 0bad7aa887 2013-12-14 kinaba: while(cur != s) 0bad7aa887 2013-12-14 kinaba: { 0bad7aa887 2013-12-14 kinaba: for(int i=0; i<s.size(); ++i) 0bad7aa887 2013-12-14 kinaba: cur[i] = min(cur[i]*2, s[i]); 0bad7aa887 2013-12-14 kinaba: ++cnt; 0bad7aa887 2013-12-14 kinaba: } 0bad7aa887 2013-12-14 kinaba: return cnt; 0bad7aa887 2013-12-14 kinaba: } 0bad7aa887 2013-12-14 kinaba: }; 0bad7aa887 2013-12-14 kinaba: 0bad7aa887 2013-12-14 kinaba: // BEGIN CUT HERE 0bad7aa887 2013-12-14 kinaba: #include <ctime> 0bad7aa887 2013-12-14 kinaba: double start_time; string timer() 0bad7aa887 2013-12-14 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 0bad7aa887 2013-12-14 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 0bad7aa887 2013-12-14 kinaba: { os << "{ "; 0bad7aa887 2013-12-14 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 0bad7aa887 2013-12-14 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 0bad7aa887 2013-12-14 kinaba: void verify_case(const int& Expected, const int& Received) { 0bad7aa887 2013-12-14 kinaba: bool ok = (Expected == Received); 0bad7aa887 2013-12-14 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 0bad7aa887 2013-12-14 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 0bad7aa887 2013-12-14 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 0bad7aa887 2013-12-14 kinaba: #define END verify_case(_, BigFatInteger().minOperations(A, B));} 0bad7aa887 2013-12-14 kinaba: int main(){ 0bad7aa887 2013-12-14 kinaba: 0bad7aa887 2013-12-14 kinaba: CASE(0) 0bad7aa887 2013-12-14 kinaba: int A = 6; 0bad7aa887 2013-12-14 kinaba: int B = 1; 0bad7aa887 2013-12-14 kinaba: int _ = 2; 0bad7aa887 2013-12-14 kinaba: END 0bad7aa887 2013-12-14 kinaba: CASE(1) 0bad7aa887 2013-12-14 kinaba: int A = 162; 0bad7aa887 2013-12-14 kinaba: int B = 1; 0bad7aa887 2013-12-14 kinaba: int _ = 4; 0bad7aa887 2013-12-14 kinaba: END 0bad7aa887 2013-12-14 kinaba: CASE(2) 0bad7aa887 2013-12-14 kinaba: int A = 999983; 0bad7aa887 2013-12-14 kinaba: int B = 9; 0bad7aa887 2013-12-14 kinaba: int _ = 5; 0bad7aa887 2013-12-14 kinaba: END 0bad7aa887 2013-12-14 kinaba: CASE(3) 0bad7aa887 2013-12-14 kinaba: int A = 360; 0bad7aa887 2013-12-14 kinaba: int B = 8; 0bad7aa887 2013-12-14 kinaba: int _ = 8; 0bad7aa887 2013-12-14 kinaba: END 0bad7aa887 2013-12-14 kinaba: CASE(4) 0bad7aa887 2013-12-14 kinaba: int A = 1000000; 0bad7aa887 2013-12-14 kinaba: int B = 1000000; 0bad7aa887 2013-12-14 kinaba: int _ = -1; 0bad7aa887 2013-12-14 kinaba: END 0bad7aa887 2013-12-14 kinaba: CASE(5) 0bad7aa887 2013-12-14 kinaba: int A = 2*3*5*7*11*13*17; 0bad7aa887 2013-12-14 kinaba: int B = 1000000; 0bad7aa887 2013-12-14 kinaba: int _ = -1; 0bad7aa887 2013-12-14 kinaba: END 0bad7aa887 2013-12-14 kinaba: 0bad7aa887 2013-12-14 kinaba: } 0bad7aa887 2013-12-14 kinaba: // END CUT HERE