Pagini recente » Cod sursa (job #445084) | Cod sursa (job #556684) | Cod sursa (job #2893996) | Cod sursa (job #1698232) | Cod sursa (job #2068138)
#include <cstdio>
using namespace std;
int nd, p, q;
int d[200], exp[200];
long long forta( long long n, int d ) {
long long s = 0;
while( n ) {
s += n / d;
n /= d;
}
return s;
}
bool sepoate( long long n ) {
for( int i = 1; i <= nd; i++ ) {
if( forta( n, d[i] ) < exp[i] * q )
return false;
}
return true;
}
long long cautcaprostu( ) {
long long r = 0, pas;
pas = 1LL << 60;
while( pas != 0 ) {
if( !sepoate( r + pas ) )
r += pas;
pas /= 2;
}
return r + 1;
}
int main( ) {
long long r;
int i, auxp;
freopen( "gfact.in", "r", stdin );
freopen( "gfact.out", "w", stdout );
scanf( "%d%d", &p, &q );
i = 2;
nd = 0;
auxp = p;
while( i * i <= auxp ) {
if( auxp % i == 0 ) {
nd++;
d[nd] = i;
while( auxp % i == 0 ) {
auxp /= i;
exp[nd]++;
}
}
i++;
}
if( auxp != 1 ) {
nd++;
d[nd] = auxp;
exp[nd] = 1;
}
// for( i = 1; i <= nd; i++ )
// printf( "%d %d\n", d[i], exp[i] );
r = cautcaprostu( );
printf( "%lld", r );
return 0;
}