#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

LL gcd(LL x, LL y){
  while(x%y){
    LL tmp = x%y;
    x=y;
    y=tmp;
  }
  return y;
}

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

