2 solutions

  • 0
    @ 2024-8-5 11:39:09
    #include <bits/stdc++.h>
    using namespace std;
    map<int,int> h;
    int main()
    {
    	int n;
    	cin>>n;
    	int	m1,m2;
    	cin>>m1>>m2;
    	for(int i=2;i<=m1;i++)
    	{
    		while(m1%i==0)
    		{
    			h[i]++;
    			m1/=i;
    		}
    	}
    	for(auto x:h)
    	{
    		x.second*=m2;
    	}
    	int maxv=-2e9;
    	bool flag=true;
    	while(n--)
    	{
    		map<int,int> p;
    		int a;
    		cin>>a;
    		for(int i=2;i<=m1;i++)
    		{
    			while(a%i==0)
    			{
    				p[i]++;
    				a/=i;
    			}
    		}
    		for(int i=2;i<=29989;i++)
    		{
    			int cnt=0;
    			if(h[i]&&!p[i])
    			{
    				flag=false;
    				break;
    			}
    			if(p[i]%h[i]==0)
    			{
    				continue;
    			}
    			while(p[i]%h[i])
    			{
    				cnt++;
    				p[i]+=p[i];
    			}
    			maxv=max(cnt,maxv);
    		}
    	}
    	if(flag&&maxv!=-2e9) cout<<maxv;
    	else cout<<-1;
    	return 0;
    }
    

    Information

    ID
    427
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    9
    Tags
    # Submissions
    9
    Accepted
    4
    Uploaded By