#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
int gcd(int a, int b) {
	if (b == 0)return a;
	return gcd(b, a%b);
}
int main() {
	int isp[100000] = {};
	vector<int> v;
	Rep(i, 2, 100000) {
		if (!isp[i]) {
			v.push_back(i);
			for(int j=2*i;j<100000;j+=i){
				isp[j] = 1;
			}
		}
	}
	int p, q; cin >> p >> q;
	int d = gcd(q,p);
	q /= d;
	int out = 1; int now = 0;
	while (q > 1) {
		if (q%v[now] == 0) {
			out*=v[now];
			while (q%v[now] == 0)q /= v[now];
		}
		else if (v[now] > (int)sqrt(q + 0.5)) {
			out *= q; q = 1;
		}
		else now++;
	}
	if (out == 1)out = 2;
	cout << out << endl;
	return 0;
}
