题目传送门
将所给的数质因数分解,当细胞数增长到所有质因数的指数都比试管数中的大,即可平均分.
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
long long n,m1,m2,tot,ans = 20000000000000,c,oo;
long long x,num[45001],sum[45001],sum1[45001],num1[45001];
bool vis[45001];
inline long long mx() {
long long s = 0,w = 1;
char ch = getchar();
while(ch < '0' || ch > '9') {
if(ch == '-') w = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9') {
s = s * 10 + (ch - '0');
ch = getchar();
}
return s * w;
}
inline void oula() {
vis[1] = 1;
for(int i = 2;i <= 45000; i++) {
if(!vis[i]) num[++tot] = i;
for(int j = 1;j <= tot; j++) {
if(num[j] * i > 45000) break;
vis[num[j]*i] = 1;
if(i % num[j] == 0) break;
}
}
}
inline void fenjie(long long a) {
for(int i = tot;i >= 1; i--) {
bool _ok = 0;
if(a % num[i] == 0) num1[++oo] = num[i],_ok = 1;
while(a % num[i] == 0) {
a = a / num[i];
sum[oo]++;
}
if(_ok) sum[oo] = sum[oo] * m2;
}
}
inline void fenjie1(long long a) {
for(int i = tot;i >= 1; i--) {
while(a % num[i] == 0) {
a = a / num[i];
sum1[num[i]]++;
}
}
}
int main() {
oula();
n = mx();
m1 = mx();
m2 = mx();
if(m1 == 1) {
printf("0");
return 0;
}
fenjie(m1);
for(int i = 1;i <= n; i++) {
x = mx();
memset(sum1,0,sizeof(sum1));
c = -1;
fenjie1(x);
for(int j = 1;j <= oo; j++) {
if(sum1[num1[j]] == 0) {
c = -1;
break;
}
if(sum1[num1[j]] >= sum[j]) {
c = max(c,(long long)1);
continue;
}
if(sum[j] % sum1[num1[j]] == 0)
c = max(c,sum[j] / sum1[num1[j]]);
else c = max(c,sum[j] / sum1[num1[j]] + 1);
}
if(c != -1)
ans = min(c,ans);
}
if(ans == 20000000000000)
printf("-1");
else
printf("%lld",ans);
return 0;
}