d6047a481e 2014-07-05 kinaba: #include <iostream> d6047a481e 2014-07-05 kinaba: #include <sstream> d6047a481e 2014-07-05 kinaba: #include <iomanip> d6047a481e 2014-07-05 kinaba: #include <vector> d6047a481e 2014-07-05 kinaba: #include <string> d6047a481e 2014-07-05 kinaba: #include <map> d6047a481e 2014-07-05 kinaba: #include <set> d6047a481e 2014-07-05 kinaba: #include <algorithm> d6047a481e 2014-07-05 kinaba: #include <numeric> d6047a481e 2014-07-05 kinaba: #include <iterator> d6047a481e 2014-07-05 kinaba: #include <functional> d6047a481e 2014-07-05 kinaba: #include <complex> d6047a481e 2014-07-05 kinaba: #include <queue> d6047a481e 2014-07-05 kinaba: #include <stack> d6047a481e 2014-07-05 kinaba: #include <cmath> d6047a481e 2014-07-05 kinaba: #include <cassert> d6047a481e 2014-07-05 kinaba: #include <tuple> d6047a481e 2014-07-05 kinaba: using namespace std; d6047a481e 2014-07-05 kinaba: typedef long long LL; d6047a481e 2014-07-05 kinaba: typedef complex<double> CMP; d6047a481e 2014-07-05 kinaba: d6047a481e 2014-07-05 kinaba: static const unsigned MODVAL = 1000000007; d6047a481e 2014-07-05 kinaba: struct mint d6047a481e 2014-07-05 kinaba: { d6047a481e 2014-07-05 kinaba: unsigned val; d6047a481e 2014-07-05 kinaba: mint():val(0){} d6047a481e 2014-07-05 kinaba: mint(int x):val(x%MODVAL) {} d6047a481e 2014-07-05 kinaba: mint(unsigned x):val(x%MODVAL) {} d6047a481e 2014-07-05 kinaba: mint(LL x):val(x%MODVAL) {} d6047a481e 2014-07-05 kinaba: }; d6047a481e 2014-07-05 kinaba: mint& operator+=(mint& x, mint y) { return x = x.val+y.val; } d6047a481e 2014-07-05 kinaba: mint& operator*=(mint& x, mint y) { return x = LL(x.val)*y.val; } d6047a481e 2014-07-05 kinaba: mint operator+(mint x, mint y) { return x+=y; } d6047a481e 2014-07-05 kinaba: mint operator*(mint x, mint y) { return x*=y; } d6047a481e 2014-07-05 kinaba: d6047a481e 2014-07-05 kinaba: int gcd(int a, int b) d6047a481e 2014-07-05 kinaba: { d6047a481e 2014-07-05 kinaba: while(a) d6047a481e 2014-07-05 kinaba: swap(a, b%=a); d6047a481e 2014-07-05 kinaba: return b; d6047a481e 2014-07-05 kinaba: } d6047a481e 2014-07-05 kinaba: d6047a481e 2014-07-05 kinaba: class ReflectiveRectangle { public: d6047a481e 2014-07-05 kinaba: int findSum(int A, int B, int bounces) d6047a481e 2014-07-05 kinaba: { d6047a481e 2014-07-05 kinaba: if(bounces%2 == 1) d6047a481e 2014-07-05 kinaba: return 0; d6047a481e 2014-07-05 kinaba: if(bounces == 0) d6047a481e 2014-07-05 kinaba: return (mint(A)*A+mint(B)*B).val; d6047a481e 2014-07-05 kinaba: d6047a481e 2014-07-05 kinaba: mint sh; d6047a481e 2014-07-05 kinaba: for(int h=1; h<bounces+2; h+=2) { d6047a481e 2014-07-05 kinaba: if(gcd(h, bounces+2) == 1) d6047a481e 2014-07-05 kinaba: sh += LL(h)*h; d6047a481e 2014-07-05 kinaba: } d6047a481e 2014-07-05 kinaba: // solution: Sigma(h*h) - Sigma_divisors(h*h) ? d6047a481e 2014-07-05 kinaba: // but no time to code...... d6047a481e 2014-07-05 kinaba: d6047a481e 2014-07-05 kinaba: return (sh*A*A+sh*B*B).val; d6047a481e 2014-07-05 kinaba: } d6047a481e 2014-07-05 kinaba: }; d6047a481e 2014-07-05 kinaba: d6047a481e 2014-07-05 kinaba: // BEGIN CUT HERE d6047a481e 2014-07-05 kinaba: #include <ctime> d6047a481e 2014-07-05 kinaba: double start_time; string timer() d6047a481e 2014-07-05 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } d6047a481e 2014-07-05 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) d6047a481e 2014-07-05 kinaba: { os << "{ "; d6047a481e 2014-07-05 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) d6047a481e 2014-07-05 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } d6047a481e 2014-07-05 kinaba: void verify_case(const int& Expected, const int& Received) { d6047a481e 2014-07-05 kinaba: bool ok = (Expected == Received); d6047a481e 2014-07-05 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; d6047a481e 2014-07-05 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } d6047a481e 2014-07-05 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); d6047a481e 2014-07-05 kinaba: #define END verify_case(_, ReflectiveRectangle().findSum(sideA, sideB, bounces));} d6047a481e 2014-07-05 kinaba: int main(){ d6047a481e 2014-07-05 kinaba: d6047a481e 2014-07-05 kinaba: CASE(0) d6047a481e 2014-07-05 kinaba: int sideA = 3; d6047a481e 2014-07-05 kinaba: int sideB = 4; d6047a481e 2014-07-05 kinaba: int bounces = 0; d6047a481e 2014-07-05 kinaba: int _ = 25; d6047a481e 2014-07-05 kinaba: END d6047a481e 2014-07-05 kinaba: CASE(1) d6047a481e 2014-07-05 kinaba: int sideA = 3; d6047a481e 2014-07-05 kinaba: int sideB = 3; d6047a481e 2014-07-05 kinaba: int bounces = 2; d6047a481e 2014-07-05 kinaba: int _ = 180; d6047a481e 2014-07-05 kinaba: END d6047a481e 2014-07-05 kinaba: CASE(2) d6047a481e 2014-07-05 kinaba: int sideA = 13; d6047a481e 2014-07-05 kinaba: int sideB = 17; d6047a481e 2014-07-05 kinaba: int bounces = 1; d6047a481e 2014-07-05 kinaba: int _ = 0; d6047a481e 2014-07-05 kinaba: END d6047a481e 2014-07-05 kinaba: CASE(3) d6047a481e 2014-07-05 kinaba: int sideA = 59325; d6047a481e 2014-07-05 kinaba: int sideB = 31785; d6047a481e 2014-07-05 kinaba: int bounces = 262142; d6047a481e 2014-07-05 kinaba: int _ = 48032850; d6047a481e 2014-07-05 kinaba: END d6047a481e 2014-07-05 kinaba: CASE(4) d6047a481e 2014-07-05 kinaba: int sideA = 1000000; d6047a481e 2014-07-05 kinaba: int sideB = 1000000; d6047a481e 2014-07-05 kinaba: int bounces = 1000000000; d6047a481e 2014-07-05 kinaba: int _ = 145972110; d6047a481e 2014-07-05 kinaba: END d6047a481e 2014-07-05 kinaba: /* d6047a481e 2014-07-05 kinaba: CASE(5) d6047a481e 2014-07-05 kinaba: int sideA = ; d6047a481e 2014-07-05 kinaba: int sideB = ; d6047a481e 2014-07-05 kinaba: int bounces = ; d6047a481e 2014-07-05 kinaba: int _ = ; d6047a481e 2014-07-05 kinaba: END d6047a481e 2014-07-05 kinaba: CASE(6) d6047a481e 2014-07-05 kinaba: int sideA = ; d6047a481e 2014-07-05 kinaba: int sideB = ; d6047a481e 2014-07-05 kinaba: int bounces = ; d6047a481e 2014-07-05 kinaba: int _ = ; d6047a481e 2014-07-05 kinaba: END d6047a481e 2014-07-05 kinaba: */ d6047a481e 2014-07-05 kinaba: } d6047a481e 2014-07-05 kinaba: // END CUT HERE