洛谷P1069


这一题其实就是分解质因数,把试管数和每种细胞分解质因数,试管有的质因数细胞也要有,才能在一段时间后装入试管。如果A被B整除,那么B的质因子A全部包括A的n次方,不论n(大于0)有多大,质因子的种类永远等于A的质因子的种类,例:当A等于2,不论是2的多少次方,永远只有2这一种质因子分解质因数: 当还能分解时,继续分解;

   #include<cstdio>
    #include<iostream>
    #define t 2147483647
    using namespace std;
    struct node{
        int number,count;
    }a[101];
    int m1,m2,n,top;
    int main()
    {
        cin>>n>>m1>>m2;int x=m1;
        for(int i=2;i<=x;i++)
        {
            if(x%i==0)
            {
                a[++top].number=i;
                while(x%i==0)//分解质因数
                {
                    x/=i;
                    a[top].count++;//找出m1;
                }
                a[top].count*=m2;//试管总数
            }
        }
        int minn=t;
        for(int i=1;i<=n;i++)
        {
            int m;
            scanf("%d",&m);
            bool b=true;
            for(int j=1;j<=top;j++)
                b=b&&(m%a[j].number==0);
            if(b)
            {
                int maxx=0;
                for(int j=1;j<=top;j++)
                {
                    int ans=0,mx=m;
                    while(mx%a[j].number==0)//分解质因数
                    {
                        mx/=a[j].number;
                        ans++;
                    }
                    ans=(a[j].count-1)/ans+1;
                    maxx=max(maxx,ans);
                }
                minn=min(minn,maxx);//最少秒时可以装进试管
            }
        }
        if(minn==t)
            cout<<"-1";//如果没有改变,输出-1
        else 
           cout<<minn;//输出结果
        return 0;
    }
原文地址:https://www.cnblogs.com/SKTskyking/p/12860498.html