Pagini recente » Borderou de evaluare (job #2973447) | Borderou de evaluare (job #2263544) | Borderou de evaluare (job #2677761) | Borderou de evaluare (job #2269078) | Cod sursa (job #2501191)
Utilizator |
Hosu Iulia Iulia25 |
Data |
29 noiembrie 2019 10:51:37 |
Problema |
Aliens |
Scor |
0 |
Compilator |
cpp-64 |
Status |
done |
Runda |
simu |
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++) {
//
// }
// }
}