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