#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define first fi;
#define second se;
using namespace std;
typedef pair<int, int> P;

int gcd(int a, int b){
    if(a < b) swap(a, b);
    if(b == 0) return a;
    return gcd(b, a % b);
}

signed main(){
    int p, q;
    cin >> p >> q;
    q /= gcd(p, q);
    int ans = 1;
    for(int i = 2; i * i <= q; i++){
        if(q % i == 0) ans *= i;
        while(q % i == 0){
            q /= i;
        }
    }
    if(q != 1) ans *= q;
    cout << ans << endl;
}