Pagini recente » Cod sursa (job #654045) | Cod sursa (job #2053957) | Cod sursa (job #1203321) | Profil DianaLuta | Cod sursa (job #1129077)
#include <fstream>
#define x first
#define y second
using namespace std;
long int n,q, COUNT,p,a;
pair<int,int> V[100005];
long long LEFT , RIGHT, MIDDLE;
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 ) V[ ++COUNT ].x=AUX,V[COUNT].y=q;
LEFT=1 , RIGHT=1LL*n*q ;
while( LEFT <= RIGHT ){
MIDDLE = ( LEFT + RIGHT ) >>1;
if( VERIF() )
RIGHT = MIDDLE -1;
else
LEFT = MIDDLE +1;
}
ofstream g("gfact.out");
g<<LEFT;
g.close();
return 0;
}