Artifact Content
Not logged in

Artifact fe758173c829bb2f07225c14258a74a98704f203


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

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 CommonMultiples { public:
	int countCommMult(vector <int> a, int lower, int upper) 
	{
		LL m = 1;
		for(int i=0; i<a.size(); ++i)
		{
			m = lcm(m, a[i]);
			if( m > upper )
				return 0;
		}
		return upper/m - (lower-1)/m;
	}
};

// 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(_, CommonMultiples().countCommMult(a, lower, upper));}
int main(){

CASE(0)
	int a_[] = {1,2,3};
	  vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_)); 
	int lower = 5; 
	int upper = 15; 
	int _ = 2; 
END
CASE(1)
	int a_[] = {1,2,4,8,16,32,64};
	  vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_)); 
	int lower = 128; 
	int upper = 128; 
	int _ = 1; 
END
CASE(2)
	int a_[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,49};
	  vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_)); 
	int lower = 1; 
	int upper = 2000000000; 
	int _ = 0; 
END
CASE(3)
	int a_[] = {1,1,1};
	  vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_)); 
	int lower = 1; 
	int upper = 2000000000; 
	int _ = 2000000000; 
END
CASE(4)
	int a_[] = {1};
	  vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_)); 
	int lower = 1; 
	int upper = 1; 
	int _ = 1; 
END
CASE(5)
	int a_[] = {2,4};
	  vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_)); 
	int lower = 4; 
	int upper = 8; 
	int _ = 2; 
END

}
// END CUT HERE