Pagini recente » Borderou de evaluare (job #498399) | Borderou de evaluare (job #693070) | Borderou de evaluare (job #963239) | Borderou de evaluare (job #1167786) | Cod sursa (job #2501221)
#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++) {
//
// }
// }
}