a2cd9490f2 2014-04-24 kinaba: #include <iostream> a2cd9490f2 2014-04-24 kinaba: #include <sstream> a2cd9490f2 2014-04-24 kinaba: #include <iomanip> a2cd9490f2 2014-04-24 kinaba: #include <vector> a2cd9490f2 2014-04-24 kinaba: #include <string> a2cd9490f2 2014-04-24 kinaba: #include <map> a2cd9490f2 2014-04-24 kinaba: #include <set> a2cd9490f2 2014-04-24 kinaba: #include <algorithm> a2cd9490f2 2014-04-24 kinaba: #include <numeric> a2cd9490f2 2014-04-24 kinaba: #include <iterator> a2cd9490f2 2014-04-24 kinaba: #include <functional> a2cd9490f2 2014-04-24 kinaba: #include <complex> a2cd9490f2 2014-04-24 kinaba: #include <queue> a2cd9490f2 2014-04-24 kinaba: #include <stack> a2cd9490f2 2014-04-24 kinaba: #include <cmath> a2cd9490f2 2014-04-24 kinaba: #include <cassert> a2cd9490f2 2014-04-24 kinaba: #include <tuple> a2cd9490f2 2014-04-24 kinaba: using namespace std; a2cd9490f2 2014-04-24 kinaba: typedef long long LL; a2cd9490f2 2014-04-24 kinaba: typedef complex<double> CMP; a2cd9490f2 2014-04-24 kinaba: a2cd9490f2 2014-04-24 kinaba: class MyLongCake { public: a2cd9490f2 2014-04-24 kinaba: int cut(int n) a2cd9490f2 2014-04-24 kinaba: { a2cd9490f2 2014-04-24 kinaba: const int N = n; a2cd9490f2 2014-04-24 kinaba: a2cd9490f2 2014-04-24 kinaba: vector<int> ps; a2cd9490f2 2014-04-24 kinaba: for(int p=2; p<=n; ++p) a2cd9490f2 2014-04-24 kinaba: { a2cd9490f2 2014-04-24 kinaba: if(n==1) a2cd9490f2 2014-04-24 kinaba: break; a2cd9490f2 2014-04-24 kinaba: if(n%p==0) { a2cd9490f2 2014-04-24 kinaba: ps.push_back(p); a2cd9490f2 2014-04-24 kinaba: while(n%p==0) n/=p; a2cd9490f2 2014-04-24 kinaba: } a2cd9490f2 2014-04-24 kinaba: } a2cd9490f2 2014-04-24 kinaba: a2cd9490f2 2014-04-24 kinaba: int cnt = 0; a2cd9490f2 2014-04-24 kinaba: for(int i=1; i<=N; ++i) a2cd9490f2 2014-04-24 kinaba: { a2cd9490f2 2014-04-24 kinaba: int cut = 0; a2cd9490f2 2014-04-24 kinaba: for(int p : ps) a2cd9490f2 2014-04-24 kinaba: if(i%p==0) a2cd9490f2 2014-04-24 kinaba: cut = 1; a2cd9490f2 2014-04-24 kinaba: cnt += cut; a2cd9490f2 2014-04-24 kinaba: } a2cd9490f2 2014-04-24 kinaba: return cnt; a2cd9490f2 2014-04-24 kinaba: } a2cd9490f2 2014-04-24 kinaba: }; a2cd9490f2 2014-04-24 kinaba: a2cd9490f2 2014-04-24 kinaba: // BEGIN CUT HERE a2cd9490f2 2014-04-24 kinaba: #include <ctime> a2cd9490f2 2014-04-24 kinaba: double start_time; string timer() a2cd9490f2 2014-04-24 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } a2cd9490f2 2014-04-24 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) a2cd9490f2 2014-04-24 kinaba: { os << "{ "; a2cd9490f2 2014-04-24 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) a2cd9490f2 2014-04-24 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } a2cd9490f2 2014-04-24 kinaba: void verify_case(const int& Expected, const int& Received) { a2cd9490f2 2014-04-24 kinaba: bool ok = (Expected == Received); a2cd9490f2 2014-04-24 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; a2cd9490f2 2014-04-24 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } a2cd9490f2 2014-04-24 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); a2cd9490f2 2014-04-24 kinaba: #define END verify_case(_, MyLongCake().cut(n));} a2cd9490f2 2014-04-24 kinaba: int main(){ a2cd9490f2 2014-04-24 kinaba: a2cd9490f2 2014-04-24 kinaba: CASE(0) a2cd9490f2 2014-04-24 kinaba: int n = 6; a2cd9490f2 2014-04-24 kinaba: int _ = 4; a2cd9490f2 2014-04-24 kinaba: END a2cd9490f2 2014-04-24 kinaba: CASE(1) a2cd9490f2 2014-04-24 kinaba: int n = 3; a2cd9490f2 2014-04-24 kinaba: int _ = 1; a2cd9490f2 2014-04-24 kinaba: END a2cd9490f2 2014-04-24 kinaba: CASE(2) a2cd9490f2 2014-04-24 kinaba: int n = 15; a2cd9490f2 2014-04-24 kinaba: int _ = 7; a2cd9490f2 2014-04-24 kinaba: END a2cd9490f2 2014-04-24 kinaba: CASE(3) a2cd9490f2 2014-04-24 kinaba: int n = 100000; a2cd9490f2 2014-04-24 kinaba: int _ = 60000; a2cd9490f2 2014-04-24 kinaba: END a2cd9490f2 2014-04-24 kinaba: /* a2cd9490f2 2014-04-24 kinaba: CASE(4) a2cd9490f2 2014-04-24 kinaba: int n = ; a2cd9490f2 2014-04-24 kinaba: int _ = ; a2cd9490f2 2014-04-24 kinaba: END a2cd9490f2 2014-04-24 kinaba: CASE(5) a2cd9490f2 2014-04-24 kinaba: int n = ; a2cd9490f2 2014-04-24 kinaba: int _ = ; a2cd9490f2 2014-04-24 kinaba: END a2cd9490f2 2014-04-24 kinaba: */ a2cd9490f2 2014-04-24 kinaba: } a2cd9490f2 2014-04-24 kinaba: // END CUT HERE