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