Problem:
幾何問題を解こう
A君は今日も幾何の問題を解いている。
幾何の問題を解く時は浮動小数点誤差に気をつけることが大事である。
浮動小数点誤差とは、2進法の有限小数で数を表す際におこる丸めによって起きる誤差である。
例えば、10進法での
0.1
は2進法では
0.00011001100110011
... という無限小数になるが、
これを有限の桁で丸める際に誤差が発生してしまう。
正の整数
p
,
q
が10進法で与えられる。
有理数
p
/
q
を有限桁数の小数で表現することができるような
b
進法（
b
は2以上の整数）を求めよ。
複数ある場合は最も小さいものを出力せよ。
Constraints
0 < p < q < 10^9
Input Format
入力は以下の形式で標準入力から与えられる。
p
q
Output Format
答えを一行に出力せよ。
Sample Input 1
1 2
Sample Output 1
2
1/2 は 2 進法で 0.1 です
Sample Input 2
21 30
Sample Output 2
10
21/30 は 10 進法で 0.7 です

Submitted solutions:

code_snippet: #include <bits/stdc++.h>

#define lol long long
#define gcd(x, y) __gcd(x, y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed(x) fixed << setprecision(x)
#define all(x) x.begin(),x.end()
using namespace std;
using pii = pair<int, int>;
template <class A, class B>
inline bool chmax(A& a, const B& b) {
  return b > a && (a = b, true);
}
template <class A, class B>
inline bool chmin(A& a, const B& b) {
  return b < a && (a = b, true);
}
template <class A>
inline A abs(A& a) {
  return (a < 0 ? -a : a);
}
bool inLine(int x, int y, int mx, int my) {
  return (x >= 0 && y >= 0 && x < mx && y < my);
}
template<class T> using max_heap=priority_queue<T>;
template<class T> using min_heap=priority_queue<T,vector<T>,greater<T>>;
template<class T> using uset=unordered_set<T>;
template<class A,class B> using umap=unordered_map<A,B>;
const lol inf = (1LL << 62);
const int MOD = (1e9) + 7;
const int mod = 998244353;
const int dx[] = {1,  0,  -1, 0, 1, 1, -1, -1, -2, -2, -2, -2,
                  -2, -1, -1, 1, 1, 0, 0,  2,  2,  2,  2,  2};
const int dy[] = {0, 1,  0, -1, 1, -1, 1, -1, -2, -1, 0, 1,
                  2, -2, 2, -2, 2, -2, 2, -2, -1, 0,  1, 2};

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int p,q;
  cin >>p>>q;
  int tmp = q/gcd(p,q);
  for(int i=2;i<tmp;i++){
    lol t = i;
    while(t < tmp){
      t *= i;
    }
    if(t == tmp){
      cout <<i<<'\n';
      return(0);
    }
  }
  cout <<tmp<<'\n';
  return (0);
}
accuracy: 0.19718309859154928
time_ms: 490
memory_kb: 3384
final_rank: 14

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()

using ll=long long;

int main(){
  ll p,q;cin>>p>>q;
  ll g=__gcd(p,q);
  p/=g;q/=g;
  for(ll i=2;;i++){
    ll j=i;
    while(j<q)j*=i;
    if(j==q){
      cout<<i<<endl;
      return 0;
    }
  }
}
accuracy: 0.19718309859154928
time_ms: 420
memory_kb: 3456
final_rank: 13

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()

using ll=long long;

int main(){
  int p,q;cin>>p>>q;
  int g=__gcd(p,q);
  p/=g;q/=g;
  for(ll i=2;;i++){
    ll j=i;
    while(j<q)j*=i;
    if(j==q){
      cout<<i<<endl;
      return 0;
    }
  }
}
accuracy: 0.19718309859154928
time_ms: 420
memory_kb: 3440
final_rank: 12

code_snippet: #define MOD_TYPE 1

#pragma region Macros

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

#if 0
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using Int = boost::multiprecision::cpp_int;
using lld = boost::multiprecision::cpp_dec_float_100;
#endif
#if 0
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
//constexpr ll MOD = ;
constexpr int INF = (int)1e9 + 10;
constexpr ll LINF = (ll)4e18;
constexpr double PI = acos(-1.0);
constexpr double EPS = 1e-10;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define REPI(i, m, n) for (int i = m; i < (int)(n); ++i)
#define repi(i, n) REPI(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

struct io_init
{
  io_init()
  {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(30) << setiosflags(ios::fixed);
  };
} io_init;
template <typename T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}
template <typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val)
{
  fill((T *)array, (T *)(array + N), val);
}
template <typename T, typename U>
constexpr istream &operator>>(istream &is, pair<T, U> &p) noexcept
{
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename U>
constexpr ostream &operator<<(ostream &os, pair<T, U> &p) noexcept
{
  os << p.first << " " << p.second;
  return os;
}
#pragma endregion

const int MAX_N = 2e7;
ll can_div[MAX_N] = {};

void init_prime()
{
  can_div[1] = -1;
  for (ll i = 2; i < MAX_N; i++)
  {
    if (can_div[i] != 0)
      continue;
    for (ll j = i + i; j < MAX_N; j += i)
      can_div[j] = i;
  }
}

inline bool is_prime(ll n)
{
  if (n <= 1)
    return false;
  return !can_div[n];
}

void solve()
{
  init_prime();
  ll p, q;
  cin >> p >> q;
  q /= gcd(p, q);
  ll ans = 1;
  for (ll i = 2; i * i <= q; i++)
  {
    if (!is_prime(i))
      continue;
    if (q % i == 0)
    {
      ans *= i;
      while (q % i == 0)
        q /= i;
    }
  }
  if (q > 1)
    ans *= q;
  cout << ans << "\n";
}

int main()
{
  solve();
}
accuracy: 1
time_ms: 310
memory_kb: 159708
final_rank: 7

code_snippet: #define MOD_TYPE 1

#pragma region Macros

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

#if 0
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using Int = boost::multiprecision::cpp_int;
using lld = boost::multiprecision::cpp_dec_float_100;
#endif
#if 0
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
//constexpr ll MOD = ;
constexpr int INF = (int)1e9 + 10;
constexpr ll LINF = (ll)4e18;
constexpr double PI = acos(-1.0);
constexpr double EPS = 1e-10;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define REPI(i, m, n) for (int i = m; i < (int)(n); ++i)
#define repi(i, n) REPI(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

struct io_init
{
  io_init()
  {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(30) << setiosflags(ios::fixed);
  };
} io_init;
template <typename T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}
template <typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val)
{
  fill((T *)array, (T *)(array + N), val);
}
template <typename T, typename U>
constexpr istream &operator>>(istream &is, pair<T, U> &p) noexcept
{
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename U>
constexpr ostream &operator<<(ostream &os, pair<T, U> &p) noexcept
{
  os << p.first << " " << p.second;
  return os;
}
#pragma endregion

const int MAX_N = 2e7;
ll can_div[MAX_N] = {};

void init_prime()
{
  can_div[1] = -1;
  for (ll i = 2; i < MAX_N; i++)
  {
    if (can_div[i] != 0)
      continue;
    for (ll j = i + i; j < MAX_N; j += i)
      can_div[j] = i;
  }
}

inline bool is_prime(ll n)
{
  if (n <= 1)
    return false;
  return !can_div[n];
}

void factorization(int n, unordered_map<ll, int> &res)
{
  if (n <= 1)
    return;
  if (!can_div[n])
  {
    ++res[n];
    return;
  }
  ++res[can_div[n]];
  factorization(n / can_div[n], res);
}

void solve()
{
  init_prime();
  ll p, q;
  cin >> p >> q;
  q /= gcd(p, q);
  unordered_map<ll, int> mp;
  factorization(q, mp);
  ll ans = 1;
  for (auto [pi, e] : mp)
    ans *= pi;
  cout << ans << "\n";
}

int main()
{
  solve();
}
accuracy: 0.028169014084507043
time_ms: 300
memory_kb: 159704
final_rank: 20

code_snippet: #include <iostream>
#include <vector>
#include <math.h>
using namespace std;

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

int main(){
	int p, q, m;
	cin >> p >> q;
	m = q/gcd(p,q);
	if(m == 1){
		cout << 1 << endl;
		return 0;
	}
	int temp = m, ans = 1;
	if(temp%2 == 0){
		ans *= 2;
		while(temp % 2 == 0){
			temp = temp/2;
			if(temp == 1) break;
		}
	}
	for(int i = 3;i<=m; i+=2){
		if(temp%i == 0){
			ans *= i;
			while(temp % i == 0){
				temp = temp/i;
				if(temp == 1) break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}
accuracy: 1
time_ms: 1290
memory_kb: 3112
final_rank: 6

code_snippet: #include "bits/stdc++.h"

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

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

int main(){
    ll p,q,ans;
    cin >> p >> q;
    
    ans=q/gcd(q,p);
    REP(i,2,ans+1){
        for(ll j=i;j<=ans;j*=i){
            if(ans==j){
                ans=i;
                goto A;
            }
        }
    }
    A:
    P(ans);
}
accuracy: 0.19718309859154928
time_ms: 790
memory_kb: 3124
final_rank: 16

code_snippet: #include "bits/stdc++.h"

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

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

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

    ll ans=q/g;
    REP(i,2,ans+1){
        for(ll j=i;j<=ans;j*=i){
            if(ans==j){
                ans=i;
                goto A;
            }
        }
    }
    A:
    P(ans);
}
accuracy: 0.19718309859154928
time_ms: 720
memory_kb: 3120
final_rank: 15

code_snippet: #include "bits/stdc++.h"

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

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

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

    ll ans=q/g;
    REP(i,2,ans/2+1){
        for(ll j=i;j<=ans;j*=i){
            if(ans==j){
                ans=i;
                goto A;
            }
        }
    }
    A:
    P(ans);
}
accuracy: 0.19718309859154928
time_ms: 320
memory_kb: 3116
final_rank: 11

code_snippet: #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);
  perr(i,2,31){
    repp(j,2,100000){
      LL tmp=1;
      rep(k,i){
        if(tmp==q){
          cout << j << endl;
          return 0;
        }
        if(tmp>(double)q/j+1){
          break;
        }
        tmp*=j;
      }
    }
  }
  cout << q << endl;
  return 0;
}
accuracy: 0.19718309859154928
time_ms: 10
memory_kb: 3064
final_rank: 8

code_snippet: #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);
  perr(i,2,30){
    repp(j,2,100000){
      LL tmp=1;
      rep(k,i){
        if(tmp==q){
          cout << j << endl;
          return 0;
        }
        if(tmp>(double)q/j){
          break;
        }
        tmp*=j;
      }
    }
  }
  cout << q << endl;
  return 0;
}
accuracy: 0.09859154929577464
time_ms: 10
memory_kb: 3056
final_rank: 18

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long p, q;
    cin >> p >> q;
    q = q / __gcd(p, q);
    int q_q = q;
    int ans = 1;
    for (int i = 2; i <= q / 2; i++) {
        if (q_q % i == 0) {
            q_q /= i;
            ans *= i;
            while (q_q % i == 0) {
                q_q /= i;
            }
        }
    }
    if (ans == 1) {
        ans = q;
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 1220
memory_kb: 3220
final_rank: 5

code_snippet: #include <bits/stdc++.h>

using namespace std;

int Prime[100000]={};

void pr(){
  Prime[0]=2;
  int tmp=1,num=1;
  while(num<100000){
    num+=2;
    int flag=0;
    for(int i=3;i<=sqrt(num);i+=2)
      if(num%i==0) flag++;
    if(flag==0) Prime[tmp++]=num;
  }
}

int gcd(int x,int y){
  return y?gcd(y,x%y):x;
}

int main(){
  pr();
  int p,q; cin>>p>>q;
  int a=q/gcd(p,q);
  //while(sqrt(a)*sqrt(a)==a) a=sqrt(a);
  for(int i=0;a/Prime[i]>=Prime[i];++i){
    int tmp=a;
    while(a%Prime[i]==0) a=a/Prime[i];
    if(tmp!=a) a*=Prime[i];
  }
  cout << a << endl;

  
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3144
final_rank: 1

code_snippet: #include <bits/stdc++.h>

using namespace std;

int Prime[100000]={};

void pr(){
  Prime[0]=2;
  int tmp=1,num=1;
  while(num<100000){
    num+=2;
    int flag=0;
    for(int i=3;i<=sqrt(num);i+=2)
      if(num%i==0) flag++;
    if(flag==0) Prime[tmp++]=num;
  }
}

int gcd(int x,int y){
  return y?gcd(y,x%y):x;
}

int main(){
  pr();
  int p,q; cin>>p>>q;
  int a=q/gcd(p,q);
  while(sqrt(a)*sqrt(a)==a) a=sqrt(a);
  for(int i=0;a/Prime[i]>=Prime[i];++i){
    int tmp=a;
    while(a%Prime[i]==0) a=a/Prime[i];
    if(tmp!=a) a*=Prime[i];
  }
  cout << a << endl;

  
  return 0;
}
accuracy: 0.16901408450704225
time_ms: 10
memory_kb: 3144
final_rank: 17

code_snippet: #include <bits/stdc++.h>

using namespace std;

int Prime[100000]={};

void pr(){
  Prime[0]=2;
  int tmp=1,num=1;
  while(num<100000){
    num+=2;
    int flag=0;
    for(int i=3;i<=sqrt(num);i+=2)
      if(num%i==0) flag++;
    if(flag==0) Prime[tmp++]=num;
  }
}

int gcd(int x,int y){
  return y?gcd(y,x%y):x;
}

int main(){
  pr();
  int p,q; cin >> p >> q;
  int a=q/gcd(p,q);
  while((int)sqrt(a)*(int)sqrt(a) == a) a=sqrt(a);
  for(int i=0;a/Prime[i]>=Prime[i];++i){
    if(a%(Prime[i]*Prime[i])==0) {a/=(Prime[i]*Prime[i]); i--;}
  }
  cout << a << endl;
  
  return 0;
}
accuracy: 0.19718309859154928
time_ms: 10
memory_kb: 3132
final_rank: 9

code_snippet: #include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

vector<int> get_prime(int n) {
    if(n <= 1) return vector<int>{};
    vector<bool> is_composite(n+1);
    vector<int> prime;
    for (int i = 2; i <= n; ++i) {
        if(!is_composite[i]) prime.push_back(i);
        for (auto &&j : prime) {
            if((ll)i*j > n) continue;
            is_composite[i*j] = true;
            if(i % j == 0) break;
        }
    }
    return prime;
}
const auto primes = get_prime(65535);

template<class T>
vector<T> prime_factor(T n){
    vector<T> res;
    for (auto &&i : primes) {
        while (n % i == 0){
            res.emplace_back(i);
            n /= i;
        }
    }
    if(n != 1) res.emplace_back(n);
    return res;
}

int main() {
    int p, q;
    cin >> p >> q;
    int g = __gcd(p, q);
    p /= g, q /= g;
    auto v = prime_factor(q);
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    int ans = 1;
    for (auto &&i : v) {
        ans *= i;
    }
    cout << ans << "\n";
    return 0;

}
accuracy: 1
time_ms: 100
memory_kb: 3236
final_rank: 2

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

int p, q;
int gcd(int x, int y){
	if(x % y == 0) return y;
	return gcd(y, x % y);
}
bool prime(int x){
	bool f = true;
	for(int i=2; i*i<=x; ++i)
		if(x % i == 0)
			f = false;
	return f;
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> p >> q;
	int g = gcd(p, q);
	q /= g;
//	cout << p / g << " " << q << "\n";
	vector<int> a;
	if(prime(q)){
		cout << q << "\n";
		return 0;
	}
	for(int i=2; i<=q; ++i){
		if(q % i == 0){
			int t = 1;
			q /= i;
			while(q % i == 0){
				++t;
				q /= i;
			}
			a.push_back(i);
		}
	}
	int ans = 1;
	for(int i=0; i<a.size(); ++i)
		ans *= a[i];
	cout << ans << "\n";
}
accuracy: 1
time_ms: 370
memory_kb: 3164
final_rank: 3

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

int p, q;
int gcd(int x, int y){
	if(x % y == 0) return y;
	return gcd(y, x % y);
}
bool prime(int x){
	bool f = true;
	for(int i=2; i*i<=x; ++i)
		if(x % i == 0)
			f = false;
	return f;
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> p >> q;
	int g = gcd(p, q);
	q /= g;
	vector<int> a, b;
	int pma = -1, pmi = 1e9;
	if(prime(q)){
		cout << q << "\n";
		return 0;
	}
	for(int i=2; i<=q; ++i){
		if(q % i == 0){
			int t = 1;
			q /= i;
			while(q % i == 0){
				++t;
				q /= i;
			}
			a.push_back(i);
			b.push_back(t);
			pmi = min(pmi, t);
			pma = max(pma, t);
		}
	}
	int ans = 1;
	if(pmi == pma){
		for(int i=0; i<a.size(); ++i)
			ans *= a[i];
	}else{
		for(int i=0; i<a.size(); ++i)
			for(int j=0; j<a[i]; ++j)
				ans *= a[i];
	}
	cout << ans << "\n";
}
accuracy: 0.19718309859154928
time_ms: 120
memory_kb: 3164
final_rank: 10

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define N 1000000000
typedef long long int ll;
ll gcd(ll a,ll b){
if(b==0)return a;
else return gcd(b,a%b);

}
queue<ll> q;
vector<bool> prime(N+1,true);
void make(ll M){
	prime[0]=prime[1]=false;
	ll i;
	for( i=2;i*i<=M+1;i++){
	if(prime[i]){
		ll j=2;
		q.push(i);
	while(i*j<M+1){
	prime[i*j]=false;
	j++;
		}

	}

	}
/*	for(;i<=M;i++){
		if(prime[i])q.push(i);
	}*/
return;

}
int main(){
ll a,b;
//cout<<"ok"<<endl;

cin>>a>>b;
//make(max(a,b));
//cout<<"ok"<<endl;
//cout<<b/gcd(a,b)<<endl;
ll c=b/gcd(a,b);
//cout<<c<<endl;
ll ans = 1;
ll ma = c;
for(ll i=2;i*i<=ma;i++){
	if(c%i==0){
	ans*=i;
	while(c%i==0)c/=i;
	}
}
/*while(!q.empty()){
	ll d = q.front();
//	cout<<d<<endl;
if(c%d==0){
	while(c%d==0)c/=d;
	ans*=d;
}
q.pop();
}*/

//cout<<ans<<' '<<c<<endl;
ans*=c;
cout<<ans<<endl;
return 0;

}
accuracy: 1
time_ms: 50
memory_kb: 124608
final_rank: 4

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define N 1000000000
typedef long long int ll;
ll gcd(ll a,ll b){
if(b==0)return a;
else return gcd(b,a%b);

}
queue<ll> q;
vector<bool> prime(N+1,true);
void make(ll M){
	prime[0]=prime[1]=false;
	ll i;
	for( i=2;i*i<=M+1;i++){
	if(prime[i]){
		ll j=2;
		q.push(i);
	while(i*j<M+1){
	prime[i*j]=false;
	j++;
		}

	}

	}
/*	for(;i<=M;i++){
		if(prime[i])q.push(i);
	}*/
return;

}
int main(){
ll a,b;
//cout<<"ok"<<endl;

cin>>a>>b;
//make(max(a,b));
//cout<<"ok"<<endl;
//cout<<b/gcd(a,b)<<endl;
ll c=b/gcd(a,b);
//cout<<c<<endl;
ll ans = 1;
ll ma = c;
for(int i=2;i*i<ma;i++){
	if(c%i==0){
	ans*=i;
	while(c%i==0)c/=i;
	}
}
/*while(!q.empty()){
	ll d = q.front();
//	cout<<d<<endl;
if(c%d==0){
	while(c%d==0)c/=d;
	ans*=d;
}
q.pop();
}*/
/*for(ll i=2;i<=c;i++){
if(c%i==0){
	
	ans*=i;
	//cout<<i<<endl;
	while(c%i==0)c/=i;
	//cout<<i<<' '<<c<<' '<<ma<<endl;
}

}*/
//cout<<c<<endl;
ans*=c;
cout<<ans<<endl;
return 0;

}
accuracy: 0.07042253521126761
time_ms: 40
memory_kb: 124568
final_rank: 19