ADDED SRM/672-U/1A-U.cpp Index: SRM/672-U/1A-U.cpp ================================================================== --- SRM/672-U/1A-U.cpp +++ SRM/672-U/1A-U.cpp @@ -0,0 +1,96 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef long long LL; +typedef complex CMP; + +class Procrastination { public: + long long findFinalAssignee(long long n) + { + map> divs; + + for(LL k=2; k*2<=n; ) { + if(n%k==0) ++n; + else if(n%k==1) --n; + + set& dn = divs[n]; + if(dn.empty()) + for(LL p=1; p*p<=n; ++p) + if(n%p==0) { + dn.insert(p); + dn.insert(n/p); + } + else if((n-1)%p==0) { + dn.insert(p); + dn.insert((n-1)/p); + } + + k = *dn.lower_bound(k+1); + } + return n; + } +}; + +// BEGIN CUT HERE +#include +double start_time; string timer() + { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } +template ostream& operator<<(ostream& os, const vector& v) + { os << "{ "; + for(typename vector::const_iterator it=v.begin(); it!=v.end(); ++it) + os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } +void verify_case(const long long& Expected, const long long& Received) { + bool ok = (Expected == Received); + if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; + cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } +#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); +#define END verify_case(_, Procrastination().findFinalAssignee(n));} +int main(){ + +CASE(0) + long long n = 3LL; + long long _ = 3LL; +END +CASE(1) + long long n = 8LL; + long long _ = 11LL; +END +CASE(2) + long long n = 20LL; + long long _ = 20LL; +END +CASE(3) + long long n = 196248LL; + long long _ = 196259LL; +END +CASE(4) + long long n = 5587021440LL; + long long _ = 5587021440LL; +END +/* +CASE(5) + long long n = LL; + long long _ = LL; +END +CASE(6) + long long n = LL; + long long _ = LL; +END +*/ +} +// END CUT HERE ADDED SRM/672-U/1B-U.cpp Index: SRM/672-U/1B-U.cpp ================================================================== --- SRM/672-U/1B-U.cpp +++ SRM/672-U/1B-U.cpp @@ -0,0 +1,116 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef long long LL; +typedef complex CMP; + +static const unsigned MODVAL = 1000000007; +struct mint +{ + unsigned val; + mint():val(0){} + mint(int x):val(x%MODVAL) {} + mint(unsigned x):val(x%MODVAL) {} + mint(LL x):val(x%MODVAL) {} +}; +mint& operator+=(mint& x, mint y) { return x = x.val+y.val; } +mint& operator-=(mint& x, mint y) { return x = x.val-y.val+MODVAL; } +mint& operator*=(mint& x, mint y) { return x = LL(x.val)*y.val; } +mint operator+(mint x, mint y) { return x+=y; } +mint operator-(mint x, mint y) { return x-=y; } +mint operator*(mint x, mint y) { return x*=y; } +mint POW(mint x, LL e) { mint v=1; for(;e;x*=x,e>>=1) if(e&1) v*=x; return v; } +mint& operator/=(mint& x, mint y) { return x *= POW(y, MODVAL-2); } +mint operator/(mint x, mint y) { return x/=y; } +vector FAC_(1,1); +mint FAC(LL n) { while( FAC_.size()<=n ) FAC_.push_back( FAC_.back()*LL(FAC_.size()) ); return FAC_[n]; } + +// nCk :: O(1) time, O(n^2) space. +vector< vector > CP_; +mint C(int n, int k) { + while( CP_.size() <= n ) { + int nn = CP_.size(); + CP_.push_back(vector(nn+1,1)); + for(int kk=1; kk memo; + mint calcExactEulerian(int n) + { + if(n == 1) + return 1; + if(memo[n] != -1) + return memo[n]; + + mint sum = 0; + for(int k=1; k +double start_time; string timer() + { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } +template ostream& operator<<(ostream& os, const vector& v) + { os << "{ "; + for(typename vector::const_iterator it=v.begin(); it!=v.end(); ++it) + os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } +void verify_case(const int& Expected, const int& Received) { + bool ok = (Expected == Received); + if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; + cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } +#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); +#define END verify_case(_, AlmostEulerianGraph().calculateGraphs(n));} +int main(){ + +CASE(0) + int n = 3; + int _ = 4; +END +CASE(1) + int n = 2; + int _ = 0; +END +CASE(2) + int n = 42; + int _ = 29010676; +END +CASE(3) + int n = 2000; + int _ = -1; +END +/* +CASE(4) + int n = ; + int _ = ; +END +*/ +} +// END CUT HERE