Artifact Content
Not logged in

Artifact 9f21bd311202df25eb189492ba73e076ba9c3ea4


#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;

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

LL lcm(LL a, LL b)
{
	return a/gcd(a,b)*b;
}

class LCMSet { public:
	string equal(vector <int> A, vector <int> B)
	{
		return is_equal(A,B) ? "Equal" : "Not equal";
	}

	bool is_equal(const vector<int>& A, const vector<int>& B)
	{
		return can_make(A, B) && can_make(B, A);
	}

	bool can_make(const vector<int>& A, const vector<int>& B)
	{
		return count_if(A.begin(), A.end(), [&](int a){return can_make(a, B);}) == A.size();
	}

	bool can_make(int a, const vector<int>& B)
	{
		LL cur = 1;
		for(int b: B) {
			if(lcm(lcm(cur, b), a) == a)
				cur = lcm(cur, b);
		}
		return a == cur;
	}
};

// 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 string& Expected, const string& 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(_, LCMSet().equal(A, B));}
int main(){

CASE(0)
	int A_[] = {2,3,4,12};
	  vector <int> A(A_, A_+sizeof(A_)/sizeof(*A_)); 
	int B_[] = {2,3,4,6};
	  vector <int> B(B_, B_+sizeof(B_)/sizeof(*B_)); 
	string _ = "Equal"; 
END
CASE(1)
	int A_[] = {4,9};
	  vector <int> A(A_, A_+sizeof(A_)/sizeof(*A_)); 
	int B_[] = {6,36};
	  vector <int> B(B_, B_+sizeof(B_)/sizeof(*B_)); 
	string _ = "Not equal"; 
END
CASE(2)
	int A_[] = {2,3,5,7,14,105};
	  vector <int> A(A_, A_+sizeof(A_)/sizeof(*A_)); 
	int B_[] = {2,3,5,6,7,30,35};
	  vector <int> B(B_, B_+sizeof(B_)/sizeof(*B_)); 
	string _ = "Equal"; 
END
CASE(3)
	int A_[] = {2,3,5,7,14,105};
	  vector <int> A(A_, A_+sizeof(A_)/sizeof(*A_)); 
	int B_[] = {2,3,5,6,7,30,36};
	  vector <int> B(B_, B_+sizeof(B_)/sizeof(*B_)); 
	string _ = "Not equal"; 
END
CASE(4)
	int A_[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
	  vector <int> A(A_, A_+sizeof(A_)/sizeof(*A_)); 
	int B_[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
	  vector <int> B(B_, B_+sizeof(B_)/sizeof(*B_)); 
	string _ = "Equal"; 
END
CASE(5)
	int A_[] = {999999999,1953125,512,1000000000};
	  vector <int> A(A_, A_+sizeof(A_)/sizeof(*A_)); 
	int B_[] = {999999999,1953125,512};
	  vector <int> B(B_, B_+sizeof(B_)/sizeof(*B_)); 
	string _ = "Equal"; 
END
CASE(6)
	int A_[] = {999999998,999999999,1000000000};
	  vector <int> A(A_, A_+sizeof(A_)/sizeof(*A_)); 
	int B_[] = {999999999,1000000000};
	  vector <int> B(B_, B_+sizeof(B_)/sizeof(*B_)); 
	string _ = "Not equal"; 
END
/*
CASE(7)
	int A_[] = ;
	  vector <int> A(A_, A_+sizeof(A_)/sizeof(*A_)); 
	int B_[] = ;
	  vector <int> B(B_, B_+sizeof(B_)/sizeof(*B_)); 
	string _ = ; 
END
CASE(8)
	int A_[] = ;
	  vector <int> A(A_, A_+sizeof(A_)/sizeof(*A_)); 
	int B_[] = ;
	  vector <int> B(B_, B_+sizeof(B_)/sizeof(*B_)); 
	string _ = ; 
END
*/
}
// END CUT HERE