Pagini recente » Cod sursa (job #1627598) | Cod sursa (job #2611803) | Cod sursa (job #58862) | Cod sursa (job #1901350) | Cod sursa (job #2251429)
#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 += a / b;
b *= i;
}
if (r < v [i])
return false;
}
}
return true;
}
inline ll bsearch (){
ll pas = (1LL << 60) , found = 0;
while (pas){
if (! check (found + pas))
found += pas;
pas = (pas >> 1);
}
return found + 1;
}
int main()
{
f >> p >> q;
desc (p);
g << bsearch ();
return 0;
}