Artifact Content
Not logged in

Artifact fa4ee92d598a53960f28bc6eab2e803569167f5c


#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 <cstring>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class ProductTriplet { public:
	long long countTriplets(int minx, int maxx, int miny, int maxy, int minz, int maxz) 
	{
		return comp(minx, maxx, miny, maxy, maxz) - comp(minx, maxx, miny, maxy, minz-1);
	}

	LL comp(LL mx, LL Mx, LL my, LL My, LL Z)
	{
		LL cnt = 0;
		for(LL x=mx; x<=Mx; )
		{
			LL Cy = Z / x;
			if( Cy < my )
				break;

			// max n such that Cy == Z / x+n
			LL n = (Z/Cy)-x;

			n = min(n, Mx-x)+1;
			cnt += n * (min(Cy,My) - my + 1);
			x += n;
		}
		return cnt;
	}
};

// 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 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(_, ProductTriplet().countTriplets(minx, maxx, miny, maxy, minz, maxz));}
int main(){

CASE(0)
	int minx = 2; 
	int maxx = 2; 
	int miny = 3; 
	int maxy = 3; 
	int minz = 6; 
	int maxz = 6; 
	long long _ = 1LL; 
END
CASE(1)
	int minx = 2; 
	int maxx = 2; 
	int miny = 3; 
	int maxy = 3; 
	int minz = 7; 
	int maxz = 7; 
	long long _ = 0LL; 
END
CASE(2)
	int minx = 6; 
	int maxx = 8; 
	int miny = 4; 
	int maxy = 5; 
	int minz = 27; 
	int maxz = 35; 
	long long _ = 4LL; 
END
CASE(3)
	int minx = 1; 
	int maxx = 458; 
	int miny = 1; 
	int maxy = 458; 
	int minz = 1; 
	int maxz = 458; 
	long long _ = 2877LL; 
END
CASE(4)
	int minx = 8176; 
	int maxx = 184561; 
	int miny = 1348; 
	int maxy = 43168; 
	int minz = 45814517; 
	int maxz = 957843164; 
	long long _ = 2365846085LL; 
END
CASE(5)
	int minx = 1; 
	int maxx = 1; 
	int miny = 1; 
	int maxy = 1; 
	int minz = 1; 
	int maxz = 1; 
	long long _ = 1LL; 
END
CASE(6)
	int minx = 1; 
	int maxx = 1000000000; 
	int miny = 1; 
	int maxy = 1000000000; 
	int minz = 1; 
	int maxz = 1000000000; 
	long long _ = -1LL; 
END

}
// END CUT HERE