1a2a57338c 2012-01-20 kinaba: #include <iostream> 1a2a57338c 2012-01-20 kinaba: #include <sstream> 1a2a57338c 2012-01-20 kinaba: #include <iomanip> 1a2a57338c 2012-01-20 kinaba: #include <vector> 1a2a57338c 2012-01-20 kinaba: #include <string> 1a2a57338c 2012-01-20 kinaba: #include <map> 1a2a57338c 2012-01-20 kinaba: #include <set> 1a2a57338c 2012-01-20 kinaba: #include <algorithm> 1a2a57338c 2012-01-20 kinaba: #include <numeric> 1a2a57338c 2012-01-20 kinaba: #include <iterator> 1a2a57338c 2012-01-20 kinaba: #include <functional> 1a2a57338c 2012-01-20 kinaba: #include <complex> 1a2a57338c 2012-01-20 kinaba: #include <queue> 1a2a57338c 2012-01-20 kinaba: #include <stack> 1a2a57338c 2012-01-20 kinaba: #include <cmath> 1a2a57338c 2012-01-20 kinaba: #include <cassert> 1a2a57338c 2012-01-20 kinaba: #include <cstring> 1a2a57338c 2012-01-20 kinaba: #ifdef __GNUC__ 1a2a57338c 2012-01-20 kinaba: #include <ext/hash_map> 1a2a57338c 2012-01-20 kinaba: #define unordered_map __gnu_cxx::hash_map 1a2a57338c 2012-01-20 kinaba: #else 1a2a57338c 2012-01-20 kinaba: #include <unordered_map> 1a2a57338c 2012-01-20 kinaba: #endif 1a2a57338c 2012-01-20 kinaba: using namespace std; 1a2a57338c 2012-01-20 kinaba: typedef long long LL; 1a2a57338c 2012-01-20 kinaba: typedef complex<double> CMP; 1a2a57338c 2012-01-20 kinaba: 1a2a57338c 2012-01-20 kinaba: static const int MODVAL = 1000000009; 1a2a57338c 2012-01-20 kinaba: 1a2a57338c 2012-01-20 kinaba: class MinskyMystery { public: 1a2a57338c 2012-01-20 kinaba: int computeAnswer(long long N) 1a2a57338c 2012-01-20 kinaba: { 1a2a57338c 2012-01-20 kinaba: return N<2 ? -1 : theCode(N); 1a2a57338c 2012-01-20 kinaba: } 1a2a57338c 2012-01-20 kinaba: 1a2a57338c 2012-01-20 kinaba: LL theCode(LL N) 1a2a57338c 2012-01-20 kinaba: { 1a2a57338c 2012-01-20 kinaba: LL counter = 1; 1a2a57338c 2012-01-20 kinaba: for(LL a=2 ;; ++a) { 1a2a57338c 2012-01-20 kinaba: {counter += N*4 + (N+a-1)/a + 1;} 1a2a57338c 2012-01-20 kinaba: if( N%a == 0 ) 1a2a57338c 2012-01-20 kinaba: return counter - N; 1a2a57338c 2012-01-20 kinaba: } 1a2a57338c 2012-01-20 kinaba: } 1a2a57338c 2012-01-20 kinaba: }; 1a2a57338c 2012-01-20 kinaba: 1a2a57338c 2012-01-20 kinaba: // BEGIN CUT HERE 1a2a57338c 2012-01-20 kinaba: #include <ctime> 1a2a57338c 2012-01-20 kinaba: double start_time; string timer() 1a2a57338c 2012-01-20 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 1a2a57338c 2012-01-20 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 1a2a57338c 2012-01-20 kinaba: { os << "{ "; 1a2a57338c 2012-01-20 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 1a2a57338c 2012-01-20 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 1a2a57338c 2012-01-20 kinaba: void verify_case(const int& Expected, const int& Received) { 1a2a57338c 2012-01-20 kinaba: bool ok = (Expected == Received); 1a2a57338c 2012-01-20 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 1a2a57338c 2012-01-20 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 1a2a57338c 2012-01-20 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 1a2a57338c 2012-01-20 kinaba: #define END verify_case(_, MinskyMystery().computeAnswer(N));} 1a2a57338c 2012-01-20 kinaba: int main(){ 1a2a57338c 2012-01-20 kinaba: 1a2a57338c 2012-01-20 kinaba: CASE(0) 1a2a57338c 2012-01-20 kinaba: long long N = 2LL; 1a2a57338c 2012-01-20 kinaba: int _ = 9; 1a2a57338c 2012-01-20 kinaba: END 1a2a57338c 2012-01-20 kinaba: CASE(1) 1a2a57338c 2012-01-20 kinaba: long long N = 3LL; 1a2a57338c 2012-01-20 kinaba: int _ = 27; 1a2a57338c 2012-01-20 kinaba: END 1a2a57338c 2012-01-20 kinaba: CASE(2) 1a2a57338c 2012-01-20 kinaba: long long N = 4LL; 1a2a57338c 2012-01-20 kinaba: int _ = 16; 1a2a57338c 2012-01-20 kinaba: END 1a2a57338c 2012-01-20 kinaba: CASE(3) 1a2a57338c 2012-01-20 kinaba: long long N = 2401LL; 1a2a57338c 2012-01-20 kinaba: int _ = 59058; 1a2a57338c 2012-01-20 kinaba: END 1a2a57338c 2012-01-20 kinaba: CASE(4) 1a2a57338c 2012-01-20 kinaba: long long N = 24LL; 1a2a57338c 2012-01-20 kinaba: int _ = 86; 1a2a57338c 2012-01-20 kinaba: END 1a2a57338c 2012-01-20 kinaba: CASE(5) 1a2a57338c 2012-01-20 kinaba: long long N = 1; 1a2a57338c 2012-01-20 kinaba: int _ = -1; 1a2a57338c 2012-01-20 kinaba: END 1a2a57338c 2012-01-20 kinaba: 1a2a57338c 2012-01-20 kinaba: } 1a2a57338c 2012-01-20 kinaba: // END CUT HERE