Pagini recente » Cod sursa (job #1351285) | Cod sursa (job #1179764) | Cod sursa (job #432200) | Rating Bustan Stefania (stefaniab) | Cod sursa (job #1307841)
#include <fstream>
#include <cmath>
using namespace std;
int main()
{
ifstream in("zero2.in");
ofstream out("zero2.out");
long factors[60][4], n, b, mn, aux;
short n_factors;
for(short i=0; i<10; ++i)
{
n_factors=0;
in>>n>>b;
for(short j=2; j<=sqrt(b); ++j)
{
if(!(b%j))
{
factors[n_factors][0]=j;
factors[n_factors][1]=1;
factors[n_factors][2]=0;
factors[n_factors][3]=0;
++n_factors;
b/=j;
}
while(!(b%j))
{
++factors[n_factors-1][1];
b/=j;
}
}
if(b>1)
{
factors[n_factors][0]=b;
factors[n_factors][1]=1;
factors[n_factors][2]=0;
factors[n_factors][3]=0;
++n_factors;
}
for(short j=2; j<=n; ++j)
{
aux=j;
for(short l=0; l<n_factors; ++l)
{
while(!(aux%factors[l][0]))
{
++factors[l][3];
aux/=factors[l][0];
}
factors[l][2]+=factors[l][3];
}
}
mn=123456789;
for(short j=0; j<n_factors; ++j)
{
if(factors[j][2]/factors[j][1]<mn)
mn=factors[j][2]/factors[j][1];
}
out<<mn<<'\n';
}
in.close(); out.close();
return 0;
}