Pagini recente » Borderou de evaluare (job #1735575) | Borderou de evaluare (job #2687946) | Borderou de evaluare (job #1772511) | Cod sursa (job #2412290) | Cod sursa (job #2501179)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream in("aliens.in");
ofstream out("aliens.out");
int n;
struct numar
{
int e2, e3, e5;
};
bool d[65][65][65];
long long lgput(long long b, int e)
{
long long ret = 1;
while (e)
{
if (e & 1)
ret *= b;
b *= b;
e >>= 1;
}
return ret;
}
int main()
{
in >> n;
d[30][30][30] = 1;
for (int i = 1; i <= n; i++)
{
int x, y;
in >> x >> y;
numar a = { 0,0,0 };
while (x % 2 == 0)
{
a.e2++;
x /= 2;
}
while (x % 3 == 0)
{
a.e3++;
x /= 3;
}
while (x % 5 == 0)
{
a.e5++;
x /= 5;
}
while (y % 2 == 0)
{
a.e2--;
y /= 2;
}
while (y % 3 == 0)
{
a.e3--;
y /= 3;
}
while (y % 5 == 0)
{
a.e5--;
y /= 5;
}
for (int e2 = (a.e2 > 0 ? 30 - a.e2 : -30 - a.e2); (a.e2 > 0 ? e2 >= -30 : e2 <= 30); (a.e2 > 0 ? e2-- : e2++))
for (int e3 = (a.e3 > 0 ? 30 - a.e3 : -30 - a.e3); (a.e3 > 0 ? e3 >= -30 : e3 <= 30); (a.e3 > 0 ? e3-- : e3++))
for (int e5 = (a.e5 > 0 ? 30 - a.e5 : -30 - a.e5); (a.e5 > 0 ? e5 >= -30 : e5 <= 30); (a.e5 > 0 ? e5-- : e5++))
d[e2 + a.e2 + 30][e3 + a.e3 + 30][e5 + a.e5 + 30] = d[e2 + a.e2 + 30][e3 + a.e3 + 30][e5 + a.e5 + 30] || d[e2 + 30][e3 + 30][e5 + 30];
}
long long maxx = 0;
for (int e2 = 0; e2 <= 30; e2++)
for (int e3 = 0; e3 <= 30; e3++)
for (int e5 = 0; e5 <= 30; e5++)
if (d[e2 + 30][e3 + 30][e5 + 30])
maxx = max(maxx, lgput(2, e2) * lgput(3, e3) * lgput(5, e5));
out << maxx;
}