Artifact Content
Not logged in

Artifact e67bc0ae357b08b2c29f6e866adf0d7ca2f401dd


#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> 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 = LL(x.val)*y.val; }
mint operator+(mint x, mint y) { return x+=y; }
mint operator*(mint x, mint y) { return x*=y; }

int gcd(int a, int b)
{
	while(a)
		swap(a, b%=a);
	return b;
}

class ReflectiveRectangle { public:
	int findSum(int A, int B, int bounces)
	{
		if(bounces%2 == 1)
			return 0;
		if(bounces == 0)
			return (mint(A)*A+mint(B)*B).val;

		mint sh;
		for(int h=1; h<bounces+2; h+=2) {
			if(gcd(h, bounces+2) == 1)
				sh += LL(h)*h;
		}
		// solution: Sigma(h*h) - Sigma_divisors(h*h) ?
		// but no time to code......

		return (sh*A*A+sh*B*B).val;
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::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(_, ReflectiveRectangle().findSum(sideA, sideB, bounces));}
int main(){

CASE(0)
	int sideA = 3; 
	int sideB = 4; 
	int bounces = 0; 
	int _ = 25; 
END
CASE(1)
	int sideA = 3; 
	int sideB = 3; 
	int bounces = 2; 
	int _ = 180; 
END
CASE(2)
	int sideA = 13; 
	int sideB = 17; 
	int bounces = 1; 
	int _ = 0; 
END
CASE(3)
	int sideA = 59325; 
	int sideB = 31785; 
	int bounces = 262142; 
	int _ = 48032850; 
END
CASE(4)
	int sideA = 1000000; 
	int sideB = 1000000; 
	int bounces = 1000000000; 
	int _ = 145972110; 
END
/*
CASE(5)
	int sideA = ; 
	int sideB = ; 
	int bounces = ; 
	int _ = ; 
END
CASE(6)
	int sideA = ; 
	int sideB = ; 
	int bounces = ; 
	int _ = ; 
END
*/
}
// END CUT HERE