Pagini recente » Cod sursa (job #556377) | Cod sursa (job #1394299) | Cod sursa (job #1463014) | Cod sursa (job #2477333) | Cod sursa (job #2251430)
#include <fstream>
using namespace std;
ifstream f ("gfact.in");
ofstream g ("gfact.out");
typedef long long ll;
ll v [100] , p , q;
inline void desc (int a){
ll o = 2 , ca = a;
while (o * o <= ca){
while (! (a % o))
a /= o , ++ v [o];
++ o;
}
if (a > 1)
v [a] = 1;
for(o = 2 ; o <= 23 ; ++ o)
v [o] *= q;
}
inline bool check (ll a){
int i;
for(i = 2 ; i <= 23 ; ++ i){
if (v [i]){
ll b = i , r = 0 , c = a;
while (a / b){
r = 1LL * (r + a / b);
b = b * i * 1LL;
}
if (r < v [i])
return false;
}
}
return true;
}
inline ll bsearch (){
ll pas = (1LL << 60) , found = 0;
while (pas){
if (! check (found + pas))
found = 1LL * (found + pas);
pas = 1LL * (pas >> 1);
}
return found + 1;
}
int main()
{
f >> p >> q;
desc (p);
g << bsearch ();
return 0;
}