982758e5e4 2011-11-29 kinaba: #include <iostream> 982758e5e4 2011-11-29 kinaba: #include <sstream> 982758e5e4 2011-11-29 kinaba: #include <iomanip> 982758e5e4 2011-11-29 kinaba: #include <vector> 982758e5e4 2011-11-29 kinaba: #include <string> 982758e5e4 2011-11-29 kinaba: #include <map> 982758e5e4 2011-11-29 kinaba: #include <set> 982758e5e4 2011-11-29 kinaba: #include <algorithm> 982758e5e4 2011-11-29 kinaba: #include <numeric> 982758e5e4 2011-11-29 kinaba: #include <iterator> 982758e5e4 2011-11-29 kinaba: #include <functional> 982758e5e4 2011-11-29 kinaba: #include <complex> 982758e5e4 2011-11-29 kinaba: #include <queue> 982758e5e4 2011-11-29 kinaba: #include <stack> 982758e5e4 2011-11-29 kinaba: #include <cmath> 982758e5e4 2011-11-29 kinaba: #include <cassert> 982758e5e4 2011-11-29 kinaba: #include <cstring> 982758e5e4 2011-11-29 kinaba: #ifdef __GNUC__ 982758e5e4 2011-11-29 kinaba: #include <ext/hash_map> 982758e5e4 2011-11-29 kinaba: #define unordered_map __gnu_cxx::hash_map 982758e5e4 2011-11-29 kinaba: #else 982758e5e4 2011-11-29 kinaba: #include <unordered_map> 982758e5e4 2011-11-29 kinaba: #endif 982758e5e4 2011-11-29 kinaba: using namespace std; 982758e5e4 2011-11-29 kinaba: typedef long long LL; 982758e5e4 2011-11-29 kinaba: typedef complex<double> CMP; 982758e5e4 2011-11-29 kinaba: 982758e5e4 2011-11-29 kinaba: class MagicDiamonds { public: 982758e5e4 2011-11-29 kinaba: long long minimalTransfer(long long n) 982758e5e4 2011-11-29 kinaba: { 982758e5e4 2011-11-29 kinaba: if( n <= 3 ) 982758e5e4 2011-11-29 kinaba: return n; 982758e5e4 2011-11-29 kinaba: for(LL p=2; p*p<=n && p<n; ++p) 982758e5e4 2011-11-29 kinaba: if( n%p == 0 ) 982758e5e4 2011-11-29 kinaba: return 1; 982758e5e4 2011-11-29 kinaba: return 2; 982758e5e4 2011-11-29 kinaba: } 982758e5e4 2011-11-29 kinaba: }; 982758e5e4 2011-11-29 kinaba: 982758e5e4 2011-11-29 kinaba: // BEGIN CUT HERE 982758e5e4 2011-11-29 kinaba: #include <ctime> 982758e5e4 2011-11-29 kinaba: double start_time; string timer() 982758e5e4 2011-11-29 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 982758e5e4 2011-11-29 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 982758e5e4 2011-11-29 kinaba: { os << "{ "; 982758e5e4 2011-11-29 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 982758e5e4 2011-11-29 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 982758e5e4 2011-11-29 kinaba: void verify_case(const long long& Expected, const long long& Received) { 982758e5e4 2011-11-29 kinaba: bool ok = (Expected == Received); 982758e5e4 2011-11-29 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 982758e5e4 2011-11-29 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 982758e5e4 2011-11-29 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 982758e5e4 2011-11-29 kinaba: #define END verify_case(_, MagicDiamonds().minimalTransfer(n));} 982758e5e4 2011-11-29 kinaba: int main(){ 982758e5e4 2011-11-29 kinaba: 982758e5e4 2011-11-29 kinaba: CASE(0) 982758e5e4 2011-11-29 kinaba: long long n = 2LL; 982758e5e4 2011-11-29 kinaba: long long _ = 2LL; 982758e5e4 2011-11-29 kinaba: END 982758e5e4 2011-11-29 kinaba: CASE(1) 982758e5e4 2011-11-29 kinaba: long long n = 4294967297LL; 982758e5e4 2011-11-29 kinaba: long long _ = 1LL; 982758e5e4 2011-11-29 kinaba: END 982758e5e4 2011-11-29 kinaba: CASE(2) 982758e5e4 2011-11-29 kinaba: long long n = 2147483647LL; 982758e5e4 2011-11-29 kinaba: long long _ = 2LL; 982758e5e4 2011-11-29 kinaba: END 982758e5e4 2011-11-29 kinaba: CASE(3) 982758e5e4 2011-11-29 kinaba: long long n = 1LL; 982758e5e4 2011-11-29 kinaba: long long _ = 1LL; 982758e5e4 2011-11-29 kinaba: END 982758e5e4 2011-11-29 kinaba: CASE(4) 982758e5e4 2011-11-29 kinaba: long long n = 1000000000000LL; 982758e5e4 2011-11-29 kinaba: long long _ = -1LL; 982758e5e4 2011-11-29 kinaba: END 982758e5e4 2011-11-29 kinaba: /* 982758e5e4 2011-11-29 kinaba: CASE(5) 982758e5e4 2011-11-29 kinaba: long long n = LL; 982758e5e4 2011-11-29 kinaba: long long _ = LL; 982758e5e4 2011-11-29 kinaba: END 982758e5e4 2011-11-29 kinaba: */ 982758e5e4 2011-11-29 kinaba: } 982758e5e4 2011-11-29 kinaba: // END CUT HERE