Cod sursa(job #2501221)

Utilizator Iulia25Hosu Iulia Iulia25 Data 29 noiembrie 2019 11:30:04
Problema Aliens Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.36 kb
#include <fstream>

using namespace std;

ifstream fin ("aliens.in");
ofstream fout ("aliens.out");

int n;
long long a[55], b[55];

long long cmmdc(long long x, long long y)	 {
	long long r = x % y;
	while (r)	 {
		x = y;
		y = r;
		r = x % y;
	}
	return y;
}

long long brut()	{
	long long x1, x2, c, ans = 0;
	for (int i = (1 << n) - 1; i; --i)	{
		x1 = x2 = c = 1;
		for (int s = i, j = 1; s; s >>= 1, ++j)	 {
      if (s & 1)	{
				x1 *= a[j];
				x2 *= b[j];
				c = cmmdc(x1, x2);
				x1 /= c, x2 /= c;
      }
		}
		if (x2 == 1)
			ans = max(ans, x1);
	}
	return ans;
}

int main()	{
  fin >> n;
  for (int i = 1; i <= n; ++i)	{
		fin >> a[i] >> b[i];
  }
  if (n <= 25)	{
		fout << brut();
		return 0;
  }
//	long long x1, x2, c, C;
//  for (int i = 1 << (n / 2) - 1; i; --i)	{
//		x1 = x2 = c = 1;
//		C = 0;
//		for (int s = i, j = 1; s; s >>= 1, ++j)	 {
//      if (s & 1)	{
//				x1 *= a[j];
//				x2 *= b[j];
//				c = cmmdc(x1, x2);
//				x1 /= c, x2 /= c;
//				C += c;
//      }
//		}
//		r[(long double)x1 / (long double)x2] = C;
//  }
//  for (int i = 1 << (n / 2 + 1) - 1; i; --i)	{
//		x1 = x2 = c = 1;
//		C = 0;
//		for (int s = i, j = 1; s; s >>= 1; ++j)	 {
//      if (s & 1)	{
//				x1 *= a[j];
//				x2 *= b[j];
//				c = cmmdc(x1, x2);
//				x1 /= c, x2 /= c;
//				C += c;
//      }
//		}
//		for (auto it = r.begin(); it != r.end(); it++)	{
//
//		}
//  }
}