Pagini recente » Cod sursa (job #2513363) | Cod sursa (job #2288777) | Cod sursa (job #267297) | Cod sursa (job #2555075) | Cod sursa (job #3169655)
#ifndef LOCAL
#pragma GCC optimize("Ofast")
#endif
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define pb push_back
#define pii pair<int, int>
using ll = long long;
using ci = const int;
using cll = const long long;
using namespace std;
const int LOG = 46;
/*******************************/
// INPUT / OUTPUT
#ifndef LOCAL
ifstream in("gfact.in");
ofstream out("gfact.out");
#define cin in
#define cout out
#endif
/*******************************/
/// GLOBAL DECLARATIONS
int P, Q;
ll ans;
vector <int> primi, puteri;
/*******************************/
/// FUNCTIONS
void ReadInput();
void Solution();
void Output();
/*******************************/
///-------------------------------------
inline void ReadInput()
{
cin >> P >> Q;
}
///-------------------------------------
inline bool ok(ll fact)
{
ll put;
ll cnt, div;
for (int i = 0 ; i < primi.size() ; ++ i)
{
div = primi[i];
cnt = 0;
put = div;
while (put <= fact)
{
cnt += fact / put;
put *= div;
}
if (cnt < puteri[i])
return false;
}
return true;
}
///-------------------------------------
inline void Solution()
{
int div = 2;
int nr = P, cnt = 0;
while (div * div <= nr)
{
if (nr % div == 0)
{
cnt = 0;
primi.push_back(div);
while (nr % div == 0)
{
nr /= div;
cnt ++;
}
puteri.push_back(cnt * Q);
}
}
if (nr != 1)
{
primi.push_back(nr);
puteri.push_back(Q);
}
ll sol = 0, step = (1LL << LOG);
while (step)
{
if (!ok(sol + step))
sol += step;
step >>= 1;
}
if (!ok(sol))
sol ++;
ans = sol;
}
///-------------------------------------
inline void Output()
{
cout << ans;
}
///-------------------------------------
int main()
{
#ifndef LOCAL
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#endif
ReadInput();
Solution();
Output();
return 0;
}