Pagini recente » Cod sursa (job #1655925) | Cod sursa (job #1713751) | Cod sursa (job #2190468) | Cod sursa (job #2219954) | Cod sursa (job #2068118)
#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 >= d )
s += ( 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;
}
r = cautcaprostu( );
printf( "%lld", r );
return 0;
}