#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

ll gcd(ll a, ll b) {
    return (b == 0 ? a : gcd(b, a % b));
}

bool isPrime(ll n) {
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            return false;
        }
    }

    return true;
}

int main() {
    ll p, q;
    cin >> p >> q;
    ll tar = q / gcd(p, q);

    if (isPrime(tar)) {
        cout << tar << endl;
        return 0;
    }

    ll ans = 1;
    for (ll i = 2; i * i <= tar; i++) {
        if (tar % i == 0) {
            ans *= i;
            while (tar % i == 0) {
                tar /= i;
            }

            if (isPrime(tar)) {
                ans *= tar;
                break;
            }
        }
    }

    cout << ans << endl;
}
