Pagini recente » Cod sursa (job #521463) | Cod sursa (job #1934938) | Cod sursa (job #317209) | Rating Veres Ionut (ionutveres) | Cod sursa (job #2251434)
#include <fstream>
#include <vector>
#define pb push_back
using namespace std;
ifstream f ("gfact.in");
ofstream g ("gfact.out");
typedef long long ll;
int p , q;
struct code{
int x , y;
};
vector <code> v;
inline void desc (ll a){
ll o = 2 , ca = a;
while (o * o <= ca){
int nr = 0;
while (! (a % o))
a /= o , ++ nr;
if (nr)
v . pb ({o , nr});
++ o;
}
if (a > 1)
v . pb ({a , 1});
int N = v . size ();
for(int i = 0 ; i < N ; ++ i)
v [i] . y *= q;
}
inline bool check (ll a){
int i , N = v . size ();
for(i = 0 ; i < N ; ++ i){
ll b = v [i] . x , r = 0 , c = a;
while (a / b){
r = 1LL * (r + a / b);
b = b * v [i] . x * 1LL;
}
if (r < v [i] . y)
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;
}