Pagini recente » Monitorul de evaluare | Diferente pentru documentatie/rating intre reviziile 22 si 21 | Cod sursa (job #153977) | Monitorul de evaluare | Cod sursa (job #3139984)
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
const long long INF = 1LL << 62;
int Fp[15], Ex[15], Nf;
long long Expf[15];
ifstream f ( "zero2.in" );
ofstream g ( "zero2.out" );
void desc ( int n )
{
Nf = 0;
for ( int d = 2; d * d <= n; d += ( d == 2 ) ? 1 : 2 )
if ( n % d == 0 )
{
Nf++;
Fp[Nf] = d;
Ex[Nf] = 0;
do
{
Ex[Nf]++;
n /= d;
}
while ( n % d == 0 );
}
if ( n > 1 )
{
Nf++;
Fp[Nf] = n;
Ex[Nf] = 1;
}
}
void expp ( int N )
{
for ( int i = 1; i <= Nf; i++ )
{
long long pp = Fp[i];
Expf[i] = 0;
while ( N >= pp )
{
int k = N / pp;
Expf[i] += pp * k * ( k - 1 ) / 2;
Expf[i] += ( N - k * pp + 1 ) * k;
pp *= Fp[i];
}
}
}
int main()
{
int N, B, t = 10;
long long nrz;
while ( t-- )
{
f >> N >> B;
desc ( B );
expp ( N );
nrz = INF;
for ( int i = 1; i <= Nf; i++ )
nrz = min ( nrz, Expf[i] / Ex[i] );
g << nrz << '\n';
}
f.close();
g.close();
return 0;
}