你可以试试这个(转的)
#include <iostream>
using namespace std;
int hashbiao[30000];
int main()
{
int n , m , t , i , j , js = 0 , maxz = 0 , max = 0 , min = 100000;
cin >> n;
cin >> m >> t;
long long shuju[n + 1];
for (i = 0 ; i < n ; i++)
cin >> shuju[i];
if (m == 1)
cout << "0" << endl;
else
{
i = 2;
while (m != 1)
{
while (m % i == 0)
{
m /= i;
hashbiao[i]++;
}
if (i > maxz)
maxz = i;
hashbiao[i++] *= t;
}
int ans = 0;
for (i = 0 ; i < n ; i++)
{
max = 0;
for (j = 2 ; j <= maxz ; j++)
{
if (hashbiao[j] == 0)
continue;
js = 0;
while (shuju[i] % j == 0)
{
shuju[i] /= j;
js++;
}
if (!js)
{
max = 100000;
break;
}
if ((hashbiao[j] - 1) / js > max)
max = (hashbiao[j] - 1) / js;
}
if (max < min)
{
min = max;
ans = max;
}
}
if (ans == 0)
cout << "-1";
else
cout << ans + 1;
}
system("pause");
return 0;
}