【P1069】 ---- 细胞分裂

链接
题意:
给N个细胞,细胞ai在t时刻的细胞数量为 ai^t ,要求 ai^t 能整除容器的数量 m1^m2 求t的最小值,如果不存在输出 -1 。
思路:
将 m1^m2 素数分解,根据每个数 ai 求出它们所需的最小的时间 t ,如果存在将 t 输出。

#include <cstdio>
using namespace std;
typedef long long ll;
ll x[30] = {0}, y[30] = {0};
ll min(ll a,ll b){
    return a < b ? a : b;
}
ll max(ll a,ll b){
    return a > b ? a : b;
}
ll compare(ll cnt,ll num){
    ll maxx = 0;
    for(ll j = 0; j < cnt; j ++){
        ll ans = 0;
        while(num % x[j] == 0){
            num /= x[j];
            ans ++;
        }
        if(ans == 0)return -1;
        maxx = max(maxx, y[j] / ans);
        if (y[j] % ans)maxx = max(maxx, y[j] / ans+1);;
    }
    return maxx;
}
int main() {
    ll N;
    scanf("%lld",&N);
    ll m1, m2;
    scanf("%lld%lld", &m1, &m2);
    ll cnt = 0;
    for(ll i = 2; m1 != 1; i ++) {
        if(m1 % i == 0) {
            while (m1 % i == 0) {
                x[cnt] = i;
                y[cnt] ++;
                m1 /= i;
            }
            cnt ++;
        }
    }
//    for(int i = 0;i < cnt; i ++)
//        printf("%d %d\n",x[i], y[i]);
    ll minn = -1;
    for(ll i = 0;i < cnt; i ++)
        y[i] *= m2;
    for(ll i = 0;i < N; i ++){
        ll num;
        scanf("%lld",&num);
        ll a = compare(cnt, num);
        if(a == -1)continue;
        if(minn == -1)minn = a;
        else minn = min(minn, a);
    }
    if(minn == -1)printf("-1\n");
    else printf("%lld\n", minn);
    return 0;
}
posted @ 2019-11-03 08:18  流浪AC  阅读(145)  评论(0编辑  收藏  举报