99eae4eb4a 2011-12-28 kinaba: #include <iostream> 99eae4eb4a 2011-12-28 kinaba: #include <sstream> 99eae4eb4a 2011-12-28 kinaba: #include <iomanip> 99eae4eb4a 2011-12-28 kinaba: #include <vector> 99eae4eb4a 2011-12-28 kinaba: #include <string> 99eae4eb4a 2011-12-28 kinaba: #include <map> 99eae4eb4a 2011-12-28 kinaba: #include <set> 99eae4eb4a 2011-12-28 kinaba: #include <algorithm> 99eae4eb4a 2011-12-28 kinaba: #include <numeric> 99eae4eb4a 2011-12-28 kinaba: #include <iterator> 99eae4eb4a 2011-12-28 kinaba: #include <functional> 99eae4eb4a 2011-12-28 kinaba: #include <complex> 99eae4eb4a 2011-12-28 kinaba: #include <queue> 99eae4eb4a 2011-12-28 kinaba: #include <stack> 99eae4eb4a 2011-12-28 kinaba: #include <cmath> 99eae4eb4a 2011-12-28 kinaba: #include <cassert> 99eae4eb4a 2011-12-28 kinaba: #include <cstring> 99eae4eb4a 2011-12-28 kinaba: #ifdef __GNUC__ 99eae4eb4a 2011-12-28 kinaba: #include <ext/hash_map> 99eae4eb4a 2011-12-28 kinaba: #define unordered_map __gnu_cxx::hash_map 99eae4eb4a 2011-12-28 kinaba: #else 99eae4eb4a 2011-12-28 kinaba: #include <unordered_map> 99eae4eb4a 2011-12-28 kinaba: #endif 99eae4eb4a 2011-12-28 kinaba: using namespace std; 99eae4eb4a 2011-12-28 kinaba: typedef long long LL; 99eae4eb4a 2011-12-28 kinaba: typedef complex<double> CMP; 99eae4eb4a 2011-12-28 kinaba: 99eae4eb4a 2011-12-28 kinaba: class MagicCandy { public: 99eae4eb4a 2011-12-28 kinaba: int whichOne(int n) 99eae4eb4a 2011-12-28 kinaba: { 99eae4eb4a 2011-12-28 kinaba: int r = n; 99eae4eb4a 2011-12-28 kinaba: while( n > 1 ) { 99eae4eb4a 2011-12-28 kinaba: int sn = int(sqrt(n)); 99eae4eb4a 2011-12-28 kinaba: r -= (sn*sn == n); 99eae4eb4a 2011-12-28 kinaba: n -= sn; 99eae4eb4a 2011-12-28 kinaba: } 99eae4eb4a 2011-12-28 kinaba: return r; 99eae4eb4a 2011-12-28 kinaba: } 99eae4eb4a 2011-12-28 kinaba: }; 99eae4eb4a 2011-12-28 kinaba: 99eae4eb4a 2011-12-28 kinaba: // BEGIN CUT HERE 99eae4eb4a 2011-12-28 kinaba: #include <ctime> 99eae4eb4a 2011-12-28 kinaba: double start_time; string timer() 99eae4eb4a 2011-12-28 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 99eae4eb4a 2011-12-28 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 99eae4eb4a 2011-12-28 kinaba: { os << "{ "; 99eae4eb4a 2011-12-28 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 99eae4eb4a 2011-12-28 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 99eae4eb4a 2011-12-28 kinaba: void verify_case(const int& Expected, const int& Received) { 99eae4eb4a 2011-12-28 kinaba: bool ok = (Expected == Received); 99eae4eb4a 2011-12-28 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 99eae4eb4a 2011-12-28 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 99eae4eb4a 2011-12-28 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 99eae4eb4a 2011-12-28 kinaba: #define END verify_case(_, MagicCandy().whichOne(n));} 99eae4eb4a 2011-12-28 kinaba: int main(){ 99eae4eb4a 2011-12-28 kinaba: CASE(0) 99eae4eb4a 2011-12-28 kinaba: int n = 5; 99eae4eb4a 2011-12-28 kinaba: int _ = 5; 99eae4eb4a 2011-12-28 kinaba: END 99eae4eb4a 2011-12-28 kinaba: CASE(1) 99eae4eb4a 2011-12-28 kinaba: int n = 9; 99eae4eb4a 2011-12-28 kinaba: int _ = 7; 99eae4eb4a 2011-12-28 kinaba: END 99eae4eb4a 2011-12-28 kinaba: CASE(2) 99eae4eb4a 2011-12-28 kinaba: int n = 20; 99eae4eb4a 2011-12-28 kinaba: int _ = 17; 99eae4eb4a 2011-12-28 kinaba: END 99eae4eb4a 2011-12-28 kinaba: CASE(3) 99eae4eb4a 2011-12-28 kinaba: int n = 5265; 99eae4eb4a 2011-12-28 kinaba: int _ = 5257; 99eae4eb4a 2011-12-28 kinaba: END 99eae4eb4a 2011-12-28 kinaba: CASE(4) 99eae4eb4a 2011-12-28 kinaba: int n = 20111223; 99eae4eb4a 2011-12-28 kinaba: int _ = 20110741; 99eae4eb4a 2011-12-28 kinaba: END 99eae4eb4a 2011-12-28 kinaba: /* 99eae4eb4a 2011-12-28 kinaba: CASE(5) 99eae4eb4a 2011-12-28 kinaba: int n = 1; 99eae4eb4a 2011-12-28 kinaba: int _ = 1; 99eae4eb4a 2011-12-28 kinaba: END 99eae4eb4a 2011-12-28 kinaba: CASE(6) 99eae4eb4a 2011-12-28 kinaba: int n = ; 99eae4eb4a 2011-12-28 kinaba: int _ = ; 99eae4eb4a 2011-12-28 kinaba: END 99eae4eb4a 2011-12-28 kinaba: CASE(7) 99eae4eb4a 2011-12-28 kinaba: int n = ; 99eae4eb4a 2011-12-28 kinaba: int _ = ; 99eae4eb4a 2011-12-28 kinaba: END 99eae4eb4a 2011-12-28 kinaba: */ 99eae4eb4a 2011-12-28 kinaba: } 99eae4eb4a 2011-12-28 kinaba: // END CUT HERE