Pagini recente » Cod sursa (job #1617724) | Cod sursa (job #2134334) | Cod sursa (job #736792) | Cod sursa (job #1545571) | Cod sursa (job #1129084)
#include <fstream>
#define x first
#define y second
using namespace std;
int n,q, COUNT;
pair<int,int> V[100005];
long long LEFT , RIGHT, MIDDLE,a,p;
bool VERIF(){
for( register long long i=1;i <= COUNT; ++i ){
p = V[i].x , a=0;
while( p <= MIDDLE && a <= V[i].y )
{ a+=MIDDLE/p ; p*=V[i].x; }
if( a < V[i].y ) return 0;
}
return 1;
}
int main()
{
ifstream f("gfact.in");
f>>n>>q; f.close();
int AUX=n;
for( register int i=2; i <= n/i ; ++i )
if( !(AUX%i) ){
V[ ++COUNT ].x=i;
while( !(AUX%i) ) {V[ COUNT ].y+=q; AUX /= i;}
}
if( AUX!=0 ) {V[ ++COUNT ].x=AUX;V[COUNT].y=q;}
LEFT=1 , RIGHT=1LL*n*q ;
while( LEFT <= RIGHT ){
MIDDLE = ( LEFT + RIGHT ) /2;
if( VERIF() )
RIGHT = MIDDLE -1;
else
LEFT = MIDDLE +1;
}
ofstream g("gfact.out");
g<<LEFT;
g.close();
return 0;
}