Artifact Content
Not logged in

Artifact 0cd8df21a9e202cb552b08c73b5f871dbde8a130


#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>
#ifdef __GNUC__
#include <ext/hash_map>
#define unordered_map __gnu_cxx::hash_map
#else
#include <unordered_map>
#endif
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class KingXNewCurrency { public:
	int howMany(int A, int B, int X)
	{
		if(A%X==0 && B%X==0)
			return -1;
		int cnt = 0;
		for(int Y=1; Y<=max(A,B); ++Y)
			if( possible(A,B,X,Y) )
				cnt++;
		return cnt;
	}

	bool possible(int A, int B, int X, int Y)
	{
		bool Aok = false;
		for(int p=0; p*X<=A; ++p)
			if( (A-p*X)%Y == 0 )
				Aok = true;
		bool Bok = false;
		for(int p=0; p*X<=B; ++p)
			if( (B-p*X)%Y == 0 )
				Bok = true;
		return Aok&&Bok;
	}
};

// 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(_, KingXNewCurrency().howMany(A, B, X));}
int main(){

CASE(0)
	int A = 5; 
	int B = 8; 
	int X = 5; 
	int _ = 5; 
END
CASE(1)
	int A = 8; 
	int B = 4; 
	int X = 2; 
	int _ = -1; 
END
CASE(2)
	int A = 7; 
	int B = 4; 
	int X = 13; 
	int _ = 1; 
END
CASE(3)
	int A = 47; 
	int B = 74; 
	int X = 44; 
	int _ = 2; 
END
CASE(4)
	int A = 128; 
	int B = 96; 
	int X = 3; 
	int _ = 65; 
END
/*
CASE(5)
	int A = ; 
	int B = ; 
	int X = ; 
	int _ = ; 
END
CASE(6)
	int A = ; 
	int B = ; 
	int X = ; 
	int _ = ; 
END
*/
}
// END CUT HERE