prithivMLmods/Coder-Stat huggingface dataset:
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
const int N = 501;
const int mod = 1e9 + 7;
int main() {
  long long n, p;
  long long ans = 1;
  scanf("%lld %lld", &n, &p);
  for (int i = 2; i * i <= p; i++) {
    if (p % i)
      continue;
    int cnt = 0;
    while (p % i == 0) {
      p /= i;
      cnt++;
      if (cnt == n) {
        ans *= i;
        cnt = 0;
      }
    }
  }
  if (p > 1 && n == 1) {
    ans *= p;
  }
  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 501;
const int mod = 1e9 + 7;
int main() {
  long long n, p;
  long long ans = 1;
  scanf("%lld %lld", &n, &p);
  for (int i = 2; 1LL * i * i <= p; i++) {
    if (p % i)
      continue;
    int cnt = 0;
    while (p % i == 0) {
      p /= i;
      cnt++;
      if (cnt == n) {
        ans *= i;
        cnt = 0;
      }
    }
  }
  if (p > 1 && n == 1) {
    ans *= p;
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03194 (C++)

Buggy submission (status: Runtime Error):
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C - Product and GCD
 */

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

/* constant */

/* typedef */

typedef long long ll;

/* global variables */

/* subroutines */

ll powll(ll a, ll b) {
  ll p = 1;
  while (b > 0) {
    if (b & 1LL)
      p *= a;
    a *= a;
    b >>= 1;
  }
  return p;
}

/* main */

int main() {
  ll n, p;
  scanf("%lld%lld", &n, &p);

  if (n == 1)
    printf("%lld\n", p);
  else {
    ll gcd = 1;
    for (ll k = 2;; k++) {
      ll e = powll(k, n);
      if (p < e)
        break;
      if (p % e == 0)
        gcd = k;
    }
    printf("%lld\n", gcd);
  }

  return 0;
}


Fixed submission:
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C - Product and GCD
 */

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

/* constant */

/* typedef */

typedef long long ll;

/* global variables */

/* subroutines */

ll powll(ll a, ll b) {
  ll p = 1;
  while (b > 0) {
    if (b & 1LL)
      p *= a;
    a *= a;
    b >>= 1;
  }
  return p;
}

/* main */

int main() {
  ll n, p;
  scanf("%lld%lld", &n, &p);

  if (n == 1)
    printf("%lld\n", p);
  else if (n >= 40)
    puts("1");
  else {
    ll gcd = 1;
    for (ll k = 2;; k++) {
      ll e = powll(k, n);
      if (p < e)
        break;
      if (p % e == 0)
        gcd = k;
    }
    printf("%lld\n", gcd);
  }

  return 0;
}
Problem p03195 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  long long n, a;
  vector<long long> v;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    v.push_back(a);
  }
  vector<long long>::iterator it = v.begin();
  vector<long long>::iterator it_end = v.end();

  while (it != it_end) {
    if (*it % 2 != 0) {
      cout << "first" << endl;
      exit(1);
    }
    it++;
  }

  cout << "second" << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  long long n, a;
  vector<long long> v;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    v.push_back(a);
  }
  vector<long long>::iterator it = v.begin();
  vector<long long>::iterator it_end = v.end();

  while (it != it_end) {
    if (*it % 2 != 0) {
      cout << "first" << endl;
      return 0;
    }
    it++;
  }

  cout << "second" << endl;

  return 0;
}
Problem p03195 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
a = [int(input()) for _ in range(N)] * [0, 0]
a.sort()
if len(a) >= 2:
    res = a[-2]
else:
    res = a[-1]
res += sum(a[:-2])
print("second" if res % 2 == 0 else "first")


Fixed submission:
N = int(input())
a = [int(input()) % 2 for _ in range(N)]
res = sum(a)
print("first" if res > 0 else "second")
Problem p03196 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <iostream>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <utility>
#include <vector>
#define mp make_pair
#define pb push_back
#define pm % 1000000007
#define llc (long long)
#define ldc (long double)
#define poc __builtin_popcount
using namespace std;

int modex(int b, int e) {
  int h = 1;
  while (e) {
    if (e & 1)
      h = llc h * b pm;
    b = llc b * b pm;
    e >>= 1;
  }
  return h;
}
int main() {
  long long n, p, res = 1;
  int ctr;
  cin >> n >> p;
  for (int i = 2; i * i <= p; i++) {
    if (p % i == 0) {
      ctr = 0;
      while (p % i == 0) {
        ctr++;
        p /= i;
      }
      ctr /= n;
      while (ctr--) {
        res *= i;
      }
    }
  }
  if (p != 1 && n == 1)
    res *= p;
  printf("%lld\n", res);
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <iostream>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <utility>
#include <vector>
#define mp make_pair
#define pb push_back
#define pm % 1000000007
#define llc (long long)
#define ldc (long double)
#define poc __builtin_popcount
using namespace std;

int modex(int b, int e) {
  int h = 1;
  while (e) {
    if (e & 1)
      h = llc h * b pm;
    b = llc b * b pm;
    e >>= 1;
  }
  return h;
}
int main() {
  long long n, p, res = 1;
  int ctr;
  cin >> n >> p;
  for (int i = 2; llc i * i <= p; i++) {
    if (p % i == 0) {
      ctr = 0;
      while (p % i == 0) {
        ctr++;
        p /= i;
      }
      ctr /= n;
      while (ctr--) {
        res *= i;
      }
    }
  }
  if (p != 1 && n == 1)
    res *= p;
  printf("%lld\n", res);
}
Problem p03196 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x, y) make_pair(x, y)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define wr cout << "----------------" << endl;
#define ppb() pop_back()
#define tr(ii, c)                                                              \
  for (__typeof((c).begin()) ii = (c).begin(); ii != (c).end(); ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x) cerr << #x << " = " << x << endl;
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
template <class T> bool umin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool umax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  // freopen("file.in", "r", stdin);
  ll n, p;
  cin >> n >> p;
  if (n == 1)
    cout << p << endl;
  else {
    int ans = 0;
    for (int i = 1; i; i++) {
      ll cur = 1;
      bool f = 1;
      for (int j = 0; j < n; j++) {
        cur *= i;
        if (cur > p) {
          f = 0;
          break;
        }
      }
      if (!f)
        break;
      if (p % cur == 0)
        ans = i;
    }
    printf("%d\n", ans);
  }
  return 0;
}


Fixed submission:
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x, y) make_pair(x, y)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define wr cout << "----------------" << endl;
#define ppb() pop_back()
#define tr(ii, c)                                                              \
  for (__typeof((c).begin()) ii = (c).begin(); ii != (c).end(); ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x) cerr << #x << " = " << x << endl;
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
template <class T> bool umin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool umax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  // freopen("file.in", "r", stdin);
  ll n, p;
  cin >> n >> p;
  if (n == 1)
    cout << p << endl;
  else {
    int ans = 1;
    for (int i = 2; i; i++) {
      ll cur = 1;
      bool f = 1;
      for (int j = 0; j < n; j++) {
        cur *= i;
        if (cur > p) {
          f = 0;
          break;
        }
      }
      if (!f)
        break;
      if (p % cur == 0)
        ans = i;
    }
    printf("%d\n", ans);
  }
  return 0;
}
Problem p03196 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e12);
const ll mod = ll(1e9) + 7;
const double pi = acos(-1);
#define rep0(i, n) for (ll(i) = 0; (i) < (n); ++(i))
#define rrep0(i, n) for (ll(i) = (n)-1; (i) >= 0; --(i))
#define rep1(i, n) for (ll(i) = 1; (i) <= (n); ++(i))
#define rrep1(i, n) for (ll(i) = (n); (i) >= 1; --(i))
#define nfor(i, a, b) for (ll(i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(), (x).end()
#define yes pf("Yes")
#define no pf("No")

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

ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b;
}

ll factorial(ll n) {
  ll t = 1;
  rep1(i, n) {
    t *= i;
    t %= mod;
  }
  return t;
}

ll power(ll a, ll b) {
  a %= mod;
  if (b == 0) {
    return 1;
  }
  ll ans = power(a, b / 2);
  ans = ans * ans % mod;
  if (b % 2 == 1) {
    ans = ans * a % mod;
  }
  return ans;
}

ll combination(ll a, ll b) {
  if ((a == b) || (b == 0)) {
    return 1;
  }
  if (a < b)
    return 0;
  ll ans = 1;
  for (ll i = 0; i < b; i++) {
    ans *= (a - i);
    ans /= (i + 1);
    ans %= mod;
  }
  return ans;
}

int main() {
  ll n, p, ans = 1;
  cin >> n >> p;
  if (n == 1) {
    pf(p);
    return 0;
  }
  for (ll i = 2; i <= p; ++i) {
    ll cnt = 0;
    while (p % i == 0) {
      ++cnt;
      p /= i;
    }
    if (cnt >= n)
      ans *= power(i, (cnt / n));
    if (i >= 3)
      ++i;
  }
  pf(ans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e12);
const ll mod = ll(1e9) + 7;
const double pi = acos(-1);
#define rep0(i, n) for (ll(i) = 0; (i) < (n); ++(i))
#define rrep0(i, n) for (ll(i) = (n)-1; (i) >= 0; --(i))
#define rep1(i, n) for (ll(i) = 1; (i) <= (n); ++(i))
#define rrep1(i, n) for (ll(i) = (n); (i) >= 1; --(i))
#define nfor(i, a, b) for (ll(i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(), (x).end()
#define yes pf("Yes")
#define no pf("No")

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

ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b;
}

ll factorial(ll n) {
  ll t = 1;
  rep1(i, n) {
    t *= i;
    t %= mod;
  }
  return t;
}

ll power(ll a, ll b) {
  a %= mod;
  if (b == 0) {
    return 1;
  }
  ll ans = power(a, b / 2);
  ans = ans * ans % mod;
  if (b % 2 == 1) {
    ans = ans * a % mod;
  }
  return ans;
}

ll combination(ll a, ll b) {
  if ((a == b) || (b == 0)) {
    return 1;
  }
  if (a < b)
    return 0;
  ll ans = 1;
  for (ll i = 0; i < b; i++) {
    ans *= (a - i);
    ans /= (i + 1);
    ans %= mod;
  }
  return ans;
}

int main() {
  ll n, p, ans = 1;
  cin >> n >> p;
  if (n == 1) {
    pf(p);
    return 0;
  }
  for (ll i = 2; i * i <= p; ++i) {
    ll cnt = 0;
    while (p % i == 0) {
      ++cnt;
      p /= i;
    }
    if (cnt >= n)
      ans *= power(i, (cnt / n));
    if (i >= 3)
      ++i;
  }
  pf(ans);
  return 0;
}
Problem p03196 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;
using i64 = std::int_fast64_t;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  i64 N, P;
  cin >> N >> P;
  map<i64, int> cnts;
  for (int i = 2; i * i < P + 1; i++) {
    int cnt = 0;
    while (P % i == 0) {
      P /= i;
      cnt++;
    }
    if (cnt > 0)
      cnts[i] = cnt;
  }
  if (P > 1)
    cnts[P]++;

  i64 res = 1;
  for (auto it = cnts.begin(); it != cnts.end(); it++) {
    res *= pow(it->first, it->second / N);
  }
  cout << res << '\n';
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;
using i64 = std::int_fast64_t;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  i64 N, P;
  cin >> N >> P;
  map<i64, int> cnts;
  for (i64 i = 2; i * i < P + 1; i++) {
    int cnt = 0;
    while (P % i == 0) {
      P /= i;
      cnt++;
    }
    if (cnt > 0)
      cnts[i] = cnt;
  }
  if (P > 1)
    cnts[P]++;

  i64 res = 1;
  for (auto it = cnts.begin(); it != cnts.end(); it++) {
    res *= pow(it->first, it->second / N);
  }
  cout << res << '\n';
  return 0;
}
Problem p03196 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
inline ll read() {
  ll x = 0, w = 1;
  char ch = 0;
  while (ch < '0' || ch > '9') {
    ch = getchar();
    if (ch == '-')
      w = -1;
  }
  while (ch <= '9' && ch >= '0') {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * w;
}
inline ll Pow(ll x, ll y) {
  ll res = 1;
  while (y) {
    if (y & 1)
      res = res * x;
    x = x * x;
    y >>= 1;
  }
  return res;
}
ll n, p, ans;
int main() {
  n = read(), p = read(), ans = 1;
  if (n == 1) {
    printf("%lld\n", p);
    return 0;
  }
  for (int i = 2; i * i <= p; ++i) {
    if (p == 1)
      break;
    if (!(p % i)) {
      ll cnt = 0;
      while (!(p % i))
        ++cnt, p /= i;
      for (int j = 1; j <= cnt / n; ++j)
        ans *= i;
    }
  }
  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
inline ll read() {
  ll x = 0, w = 1;
  char ch = 0;
  while (ch < '0' || ch > '9') {
    ch = getchar();
    if (ch == '-')
      w = -1;
  }
  while (ch <= '9' && ch >= '0') {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * w;
}
inline ll Pow(ll x, ll y) {
  ll res = 1;
  while (y) {
    if (y & 1)
      res = res * x;
    x = x * x;
    y >>= 1;
  }
  return res;
}
ll n, p, ans;
int main() {
  n = read(), p = read(), ans = 1;
  if (n == 1) {
    printf("%lld\n", p);
    return 0;
  }
  for (ll i = 2; i * i <= p; ++i) {
    if (p == 1)
      break;
    if (!(p % i)) {
      ll cnt = 0;
      while (!(p % i))
        ++cnt, p /= i;
      for (int j = 1; j <= cnt / n; ++j)
        ans *= i;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03196 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll n, p, ans;
  cin >> n >> p;
  if (n == 1) {
    cout << p << endl;
    return 0;
  }
  for (ll i = 1; i <= p; i++) {
    ll gcd = pow(i, n);
    if (p % gcd == 0) {
      ans = i;
    } else if (gcd > p) {
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll n, p, ans;
  cin >> n >> p;
  if (n == 1) {
    cout << p << endl;
    return 0;
  }
  if (n > 40) {
    cout << 1 << endl;
    return 0;
  }
  for (ll i = 1; i <= p; i++) {
    ll gcd = pow(i, n);
    if (p % gcd == 0) {
      ans = i;
    } else if (gcd > p) {
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03196 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(c) c.begin(), c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int main() {
  ll N, P;
  cin >> N >> P;
  ll i = 2, gcd = 1;
  ll count;
  while (pow(i, N) <= P) {
    count = 0;
    while (true) {
      if (P % i == 0) {
        count++;
        P /= i;
      } else {
        gcd *= ll(pow(i, (count / N)));
        break;
      }
    }

    if (i == 2) {
      i++;
    } else {
      i += 2;
    }
  }
  cout << gcd;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(c) c.begin(), c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int main() {
  ll N, P;
  cin >> N >> P;
  ll i = 2, gcd = 1;
  ll count;

  if (N == 1) {
    cout << P;
    return 0;
  }
  while (pow(i, 2) <= P) {
    count = 0;
    while (true) {
      if (P % i == 0) {
        count++;
        P /= i;
      } else {
        gcd *= ll(pow(i, (count / N)));
        break;
      }
    }

    if (i == 2) {
      i++;
    } else {
      i += 2;
    }
  }
  cout << gcd;
  return 0;
}
Problem p03196 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

ll N, P;
ll mx = 1;

int main() {
  scanf("%lld%lld", &N, &P);

  for (int i = 2; i * i <= P; ++i) {
    int cnt = 0;
    while (!(P % i)) {
      cnt++;
      if (!(cnt % N))
        mx *= i;
      P /= i;
    }
  }

  if (N == 1)
    mx *= P;

  printf("%lld\n", mx);
}

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

typedef long long ll;

ll N, P;
ll mx = 1;

int main() {
  scanf("%lld%lld", &N, &P);

  for (ll i = 2; i * i <= P; ++i) {
    int cnt = 0;
    while (!(P % i)) {
      cnt++;
      if (!(cnt % N))
        mx *= i;
      P /= i;
    }
  }

  if (N == 1)
    mx *= P;

  printf("%lld\n", mx);
}
Problem p03196 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
ll mod = 1e9 + 7;

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> res;
  for (int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) {
    res[n]++;
  }
  return res;
}

ll mpow(ll x, ll n) {
  ll ans = 1;
  while (n > 0) {
    if (n & 1) {
      ans = ans * x;
    }
    x = x * x;
    n >>= 1;
  }
  return ans;
}

int main() {
  ll n, p;
  cin >> n >> p;
  ll ans = 1;
  map<ll, ll> c = prime_factor(p);
  for (auto p : c) {
    ll temp = p.second / n;
    ans *= mpow(p.first, temp);
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
ll mod = 1e9 + 7;

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) {
    res[n]++;
  }
  return res;
}

ll mpow(ll x, ll n) {
  ll ans = 1;
  while (n > 0) {
    if (n & 1) {
      ans = ans * x;
    }
    x = x * x;
    n >>= 1;
  }
  return ans;
}

int main() {
  ll n, p;
  cin >> n >> p;
  ll ans = 1;
  map<ll, ll> c = prime_factor(p);
  for (auto p : c) {
    ll temp = p.second / n;
    ans *= mpow(p.first, temp);
  }
  cout << ans << endl;
}
Problem p03196 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
typedef pair<ll, ll> cp2;
typedef pair<ll, cp2> cp3;
#define fi first
#define se second
#define sec se.fi
#define thr se.se
const ll mod = 1000000007;
//              123456789

///////////////////////////////////////////////
//
//
///////////////////////////////////////////////

////////////////////////////////////////////////
////////////////////////////////////////////////

ll N;
ll P;
ll ans = 1;
ll x = 2;
ll num;

ll calc(ll a, ll b) {
  ll res = 1;
  ll temp = a;
  while (b) {
    if (b % 2)
      res *= temp;
    if (res > P) {
      res = mod * mod;
      break;
    }
    temp = temp * temp;
    b /= 2;
  }
  return res;
}

int main() {

  cin >> N >> P;
  num = calc(x, N);

  if (N > 50) {
    puts("1");
  } else {
    while (num <= P) {
      if (P % num == 0)
        ans = x;
      // cout<<x<<";"<<num<<endl;
      x++;
      num = calc(x, N);
    }

    cout << ans << endl;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
typedef pair<ll, ll> cp2;
typedef pair<ll, cp2> cp3;
#define fi first
#define se second
#define sec se.fi
#define thr se.se
const ll mod = 1000000007;
//              123456789

///////////////////////////////////////////////
//
//
///////////////////////////////////////////////

////////////////////////////////////////////////
////////////////////////////////////////////////

ll N;
ll P;
ll ans = 1;
ll x = 2;
ll num;

ll calc(ll a, ll b) {
  ll res = 1;
  ll temp = a;
  while (b) {
    if (b % 2)
      res *= temp;
    if (res > P) {
      res = mod * mod;
      break;
    }
    temp = temp * temp;
    b /= 2;
  }
  return res;
}

int main() {

  cin >> N >> P;
  num = calc(x, N);

  if (N > 50) {
    puts("1");
  } else if (N == 1) {
    cout << P << endl;
  } else {
    while (num <= P) {
      if (P % num == 0)
        ans = x;
      // cout<<x<<";"<<num<<endl;
      x++;
      num = calc(x, N);
    }

    cout << ans << endl;
  }

  return 0;
}
Problem p03196 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <utility>
#include <vector>
#include <vector>
#define ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define ll long long
#define pb push_back
using namespace std;

const int N = 2e6, PI = 3.14159265359, M = 1e9 + 7;
typedef pair<ll, ll> pii;
map<ll, ll> dp;
ll a[N], ans = 0;
map<pii, ll> ma;
vector<pii> v, v1;

int main() {
  ll n, p;
  cin >> n >> p;
  for (int i = 2; i * i <= p; i++) {
    if (p % i == 0) {
      ll cnt = 0;
      while (p % i == 0) {
        p /= i;
        cnt++;
      }
      v.pb({i, cnt});
    }
  }
  if (p != 1) {
    v.pb({p, 1});
  }
  ll ans = 1;
  for (int i = 0; i < v.size(); i++) {
    ll t = v[i].ss / n;
    while (t--) {
      ans *= v[i].ff;
    }
  }
  cout << ans;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <utility>
#include <vector>
#include <vector>
#define ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define ll long long
#define pb push_back
using namespace std;

const int N = 2e6, PI = 3.14159265359, M = 1e9 + 7;
typedef pair<ll, ll> pii;
map<ll, ll> dp;
ll a[N], ans = 0;
map<pii, ll> ma;
vector<pii> v, v1;

int main() {
  ll n, p;
  cin >> n >> p;
  for (ll int i = 2; i * i <= p; i++) {
    if (p % i == 0) {
      ll cnt = 0;
      while (p % i == 0) {
        p /= i;
        cnt++;
      }
      v.pb({i, cnt});
    }
  }
  if (p != 1) {
    v.pb({p, 1});
  }
  ll ans = 1;
  for (int i = 0; i < v.size(); i++) {
    ll t = v[i].ss / n;
    while (t--) {
      ans *= v[i].ff;
    }
  }
  cout << ans;
  return 0;
}
Problem p03196 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()
#define dump(x) cout << #x << " = " << (x) << endl

ll N, P;

int main() {
  ll a = 1;
  cin >> N >> P;
  if (N == 1) {
    cout << P << endl;
    return 0;
  }

  for (int i = 2; i * i <= P; ++i) {
    if (P % i == 0) {
      int c = 0;
      while (P % i == 0) {
        P /= i;
        ++c;
      }
      c /= N;
      rep(tt, c) { a = a * i; }
    }
  }
  cout << a << endl;
  return 0;
}

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()
#define dump(x) cout << #x << " = " << (x) << endl

ll N, P;

int main() {
  ll a = 1;
  cin >> N >> P;
  if (N == 1) {
    cout << P << endl;
    return 0;
  }

  for (ll i = 2; i * i <= P; ++i) {
    if (P % i == 0) {
      int c = 0;
      while (P % i == 0) {
        P /= i;
        ++c;
      }
      c /= N;
      rep(tt, c) { a = a * i; }
    }
  }
  cout << a << endl;
  return 0;
}
Problem p03196 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
const int maxN = 2e5 + 10;
const int INF = 999999999;

ll n, p;
ll a[maxN];
ll q[maxN];
struct node {
  ll x, t;
};

ll tot = 0ll;
ll power(ll x, ll t) {
  if (t == 0)
    return 1;
  ll y = power(x, t / 2);
  y = y * y;
  if (t % 2 == 1)
    y = y * x;
  return y;
}
bool check(ll x) {
  if (p % (power(x, n)) == 0)
    return true;
  else
    return false;
}
int main() {
  scanf("%lld%lld", &n, &p);
  if (n == 1) {
    printf("%lld\n", p);
    return 0;
  }
  ll ans = 0;
  for (ll i = 1; power(i, n) <= p; i++) {
    if (p % (power(i, n)) == 0)
      ans = max(ans, i);
  }
  printf("%lld\n", ans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
const int maxN = 2e5 + 10;
const int INF = 999999999;

ll n, p;
ll a[maxN];
ll q[maxN];
struct node {
  ll x, t;
};

ll tot = 0ll;
ll power(ll x, ll t) {
  if (t == 0)
    return 1;
  ll y = power(x, t / 2);
  y = y * y;
  if (t % 2 == 1)
    y = y * x;
  return y;
}
bool check(ll x) {
  if (p % (power(x, n)) == 0)
    return true;
  else
    return false;
}
int main() {
  scanf("%lld%lld", &n, &p);
  if (n == 1) {
    printf("%lld\n", p);
    return 0;
  }
  ll ans = 0;
  for (ll i = 1; n * log(i) <= log(p) + 1; i++) {
    if (p % (power(i, n)) == 0)
      ans = max(ans, i);
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03196 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n, p, cnt = 1;
ll ans, tmp;
int main() {
  cin >> n >> p;
  if (n == 1) {
    cout << p << endl;
    return 0;
  }
  while (1) {
    tmp = 1;
    for (long long i = 1; i <= n; i++)
      tmp *= cnt;
    if (tmp > p)
      break;
    if (p % tmp == 0)
      ans = cnt;
    cnt++;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n, p, cnt = 1;
ll ans, tmp;
int main() {
  cin >> n >> p;
  if (n >= 50) {
    cout << 1 << endl;
    return 0;
  }
  if (n == 1) {
    cout << p << endl;
    return 0;
  }
  while (1) {
    tmp = 1;
    for (long long i = 1; i <= n; i++)
      tmp *= cnt;
    if (tmp > p)
      break;
    if (p % tmp == 0)
      ans = cnt;
    cnt++;
  }
  cout << ans << endl;
  return 0;
}
Problem p03196 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Vec = vector<ll>;
#define FOR(i, m, n) for (ll(i) = (m); (i) < (n); (i)++)
#define FORN(i, m, n) for (ll(i) = (m); (i) <= (n); (i)++)
#define FORR(i, m, n) for (ll(i) = (m); (i) >= (n); (i)--)
#define rep(i, n) FOR(i, 0, n)
#define repn(i, n) FORN(i, 1, n)
#define repr(i, n) FORR(i, n, 0)
#define repnr(i, n) FORR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second

const ll INF = 1e9 + 1;
const ll LINF = 1e18 + 1;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void) {
  ll n, p;
  cin >> n >> p;
  if (n == 1) {
    co(p);
    return 0;
  }
  ll ans = 0;
  repn(i, p) {
    ll num = 1;
    rep(j, n) num *= i;
    if (num > p)
      break;
    else if (!(p % num))
      ans = i;
  }
  co(ans);

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Vec = vector<ll>;
#define FOR(i, m, n) for (ll(i) = (m); (i) < (n); (i)++)
#define FORN(i, m, n) for (ll(i) = (m); (i) <= (n); (i)++)
#define FORR(i, m, n) for (ll(i) = (m); (i) >= (n); (i)--)
#define rep(i, n) FOR(i, 0, n)
#define repn(i, n) FORN(i, 1, n)
#define repr(i, n) FORR(i, n, 0)
#define repnr(i, n) FORR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second

const ll INF = 1e9 + 1;
const ll LINF = 1e18 + 1;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void) {
  ll n, p;
  cin >> n >> p;
  if (n == 1) {
    co(p);
    return 0;
  } else if (n >= 50) {
    co(1);
    return 0;
  }
  ll ans = 0;
  repn(i, p) {
    ll num = 1;
    rep(j, n) num *= i;
    if (num > p)
      break;
    else if (!(p % num))
      ans = i;
  }
  co(ans);

  return 0;
}
Problem p03196 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define mod 1000000007    // 10^9+7
#define INF 1000000000000 // 10^12
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < n; i++)
int n, p;
int ans = 1, x = 1;
signed main() {
  cin >> n >> p;
  for (int i = 2; x <= p; i++) {
    x = 1;
    for (int j = 0; j < n; j++) {
      x *= i;
      if (x > p) {
        cout << ans << endl;
        return 0;
      }
    }
    if (p % x == 0)
      ans = i;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define mod 1000000007    // 10^9+7
#define INF 1000000000000 // 10^12
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < n; i++)
int n, p;
int ans = 1, x = 1;
signed main() {
  cin >> n >> p;
  if (n == 1) {
    cout << p << endl;
    return 0;
  }
  for (int i = 2; x <= p; i++) {
    x = 1;
    for (int j = 0; j < n; j++) {
      x *= i;
      if (x > p) {
        cout << ans << endl;
        return 0;
      }
    }
    if (p % x == 0)
      ans = i;
  }
  cout << ans << endl;
  return 0;
}
Problem p03196 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, P;
  cin >> N >> P;
  long long r = 1;
  if (N == 1) {
    r = P;
  } else {
    for (int i = 2; i * i <= P; ++i) {
      int c = 0;
      while (P % i == 0) {
        ++c;
        P /= i;
      }
      for (int j = 0; j < c / N; ++j)
        r *= i;
    }
  }
  cout << r << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, P;
  cin >> N >> P;
  long long r = 1;
  if (N == 1) {
    r = P;
  } else {
    for (long long i = 2; i * i <= P; ++i) {
      int c = 0;
      while (P % i == 0) {
        ++c;
        P /= i;
      }
      for (int j = 0; j < c / N; ++j)
        r *= i;
    }
  }
  cout << r << endl;
}
Problem p03196 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ll n, p;
  cin >> n >> p;

  vector<ll> div;
  for (ll i = 1; i * i <= p; i++) {
    if (p % i == 0) {
      div.push_back(i);
      div.push_back(p / i);
    }
  }

  ll ans = 1;
  for (ll now : div) {
    if (now == 1)
      continue;
    ll cnt = 0;
    ll d = now;
    while (p % d == 0) {
      cnt++;
      d *= now;
    }
    if (cnt >= n)
      ans = max(ans, now);
  }

  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ll n, p;
  cin >> n >> p;

  vector<ll> div;
  for (ll i = 1; i * i <= p; i++) {
    if (p % i == 0) {
      div.push_back(i);
      div.push_back(p / i);
    }
  }

  ll ans = 1;
  for (ll now : div) {
    if (now == 1)
      continue;
    ll cnt = 0;
    ll pp = p;
    while (true) {
      if (pp % now == 0) {
        cnt++;
        pp /= now;
      } else
        break;
    }
    if (cnt >= n)
      ans = max(ans, now);
  }

  cout << ans << endl;
}
Problem p03196 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define _repargs(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(...) _repargs(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T> inline void output(T a, int p = 0) {
  if (p)
    cout << fixed << setprecision(p) << a << "\n";
  else
    cout << a << "\n";
}
// end of template

ll P;

bool po(ll a, ll b) {
  ll c = 1;
  rep(i, b) { c *= a; }
  return c;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  // source code
  int N;
  cin >> N;
  ll ret = 1;
  ll P;
  cin >> P;
  if (N > 40) {
    output(1);
    return 0;
  }

  ll a = 2;
  while (1) {
    ll b = 1;
    ll ok = true;
    rep(i, N) {
      b *= a;
      if (b > P) {
        ok = false;
        break;
      }
    }
    if (!ok)
      break;
    if (P % b == 0) {
      ret = a;
    }
    a++;
  }
  output(ret);

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define _repargs(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(...) _repargs(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T> inline void output(T a, int p = 0) {
  if (p)
    cout << fixed << setprecision(p) << a << "\n";
  else
    cout << a << "\n";
}
// end of template

ll P;

bool po(ll a, ll b) {
  ll c = 1;
  rep(i, b) { c *= a; }
  return c;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  // source code
  int N;
  cin >> N;
  ll ret = 1;
  ll P;
  cin >> P;
  if (N == 1) {
    output(P);
    return 0;
  }
  if (N > 40) {
    output(1);
    return 0;
  }

  ll a = 2;
  while (1) {
    ll b = 1;
    ll ok = true;
    rep(i, N) {
      b *= a;
      if (b > P) {
        ok = false;
        break;
      }
    }
    if (!ok)
      break;
    if (P % b == 0) {
      ret = a;
    }
    a++;
  }
  output(ret);

  return 0;
}
Problem p03196 (C++)

Buggy submission (status: Time Limit Exceeded):
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

/*
ll pw(ll a, ll b) {
        ll ans = 1; while (b) {
                while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
                ans = (ans * a) % MOD, --b;
        } return ans;
}
*/

ll n, p;

int main() {
#ifdef FASTIO
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
  cin >> p >> n;
  ll ans = 1;
  for (int i = 2; i * i <= n; ++i) {
    if (n % i != 0)
      continue;
    int cnt = 0;
    while (n % i == 0)
      n /= i, ++cnt;
    while (cnt >= p)
      cnt -= p, ans *= i;
  }
  if (n != 1 && p == 1)
    ans *= n;
  cout << ans << "\n";
  return 0;
}


Fixed submission:
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

/*
ll pw(ll a, ll b) {
        ll ans = 1; while (b) {
                while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
                ans = (ans * a) % MOD, --b;
        } return ans;
}
*/

ll n, p;

int main() {
#ifdef FASTIO
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
  cin >> p >> n;
  ll ans = 1;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i != 0)
      continue;
    int cnt = 0;
    while (n % i == 0)
      n /= i, ++cnt;
    while (cnt >= p)
      cnt -= p, ans *= i;
  }
  if (n != 1 && p == 1)
    ans *= n;
  cout << ans << "\n";
  return 0;
}
Problem p03196 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<ll, int> P;

int main() {
  ll n, p;
  cin >> n >> p;
  vector<P> v;
  for (int i = 2; i * i <= p; i++) {
    if (p % i == 0) {
      int e = 0;
      while (p % i == 0) {
        p /= i;
        e++;
      }
      v.push_back(P(i, e));
    }
  }
  if (p > 1)
    v.push_back(P(p, 1));
  ll ans = 1;
  for (int i = 0; i < v.size(); i++) {
    int e = v[i].second;
    ll q = v[i].first;
    for (int j = 0; j < e / n; j++) {
      ans *= q;
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<ll, int> P;

int main() {
  ll n, p;
  cin >> n >> p;
  vector<P> v;
  for (ll i = 2; i * i <= p; i++) {
    if (p % i == 0) {
      int e = 0;
      while (p % i == 0) {
        p /= i;
        e++;
      }
      v.push_back(P(i, e));
    }
  }
  if (p > 1)
    v.push_back(P(p, 1));
  ll ans = 1;
  for (int i = 0; i < v.size(); i++) {
    int e = v[i].second;
    ll q = v[i].first;
    for (int j = 0; j < e / n; j++) {
      ans *= q;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03196 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm = 1000000000;
ll MM = mm + 7;
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.141592653589793

int main() {
  ll n, p;
  cin >> n >> p;
  if (n == 1)
    cout << p << endl;
  else {
    ll i = 0;
    ll ans;
    ll k = 0;
    while (k <= p) {
      i++;
      k = pow(i, n);
      if (p % k == 0)
        ans = i;
    }
    cout << ans << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm = 1000000000;
ll MM = mm + 7;
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.141592653589793

int main() {
  ll n, p;
  cin >> n >> p;
  if (n == 1)
    cout << p << endl;
  else if (n >= 50)
    cout << 1 << endl;
  else {
    ll i = 0;
    ll ans;
    ll k = 0;
    while (k <= p) {
      i++;
      k = pow(i, n);
      if (p % k == 0)
        ans = i;
    }
    cout << ans << endl;
  }
}
Problem p03196 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
vector<long long> d;
int main(void) {
  lint n;
  cin >> n;
  long long p;
  cin >> p;
  if (n == 1) {
    cout << p << endl;
    return 0;
  }
  for (int i = 2; i * i <= p; i++) {
    while (p % i == 0) {
      d.push_back(i);
      p /= i;
    }
  }
  if (p != 1)
    d.push_back(p);
  int cnt = 1;
  lint ans = 1;
  for (int i = 0; i < (int)d.size() - 1; i++) {
    if (d[i] == d[i + 1]) {
      cnt++;
    } else {
      if (cnt >= n)
        ans *= pow(d[i], (cnt / n));
      cnt = 1;
    }
    if (i == (int)d.size() - 2) {
      if (cnt >= n)
        ans *= pow(d[i], (cnt / n));
    }
  }
  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
vector<long long> d;
int main(void) {
  lint n;
  cin >> n;
  long long p;
  cin >> p;
  if (n == 1) {
    cout << p << endl;
    return 0;
  }
  for (long long i = 2; i * i <= p; i++) {
    while (p % i == 0) {
      d.push_back(i);
      p /= i;
    }
  }
  if (p != 1)
    d.push_back(p);
  int cnt = 1;
  lint ans = 1;
  for (int i = 0; i < (int)d.size() - 1; i++) {
    if (d[i] == d[i + 1]) {
      cnt++;
    } else {
      if (cnt >= n)
        ans *= pow(d[i], (cnt / n));
      cnt = 1;
    }
    if (i == (int)d.size() - 2) {
      if (cnt >= n)
        ans *= pow(d[i], (cnt / n));
    }
  }
  cout << ans << endl;

  return 0;
}
Problem p03196 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  ll n, p, ans = 1;
  cin >> n >> p;

  if (n == 1) {
    cout << p << endl;
    return 0;
  }
  for (int i = 2; i * i <= p; i++) {
    if (p % i != 0)
      continue;
    ll num = 0;
    while (p % i == 0) {
      p /= i;
      num++;
      if (num == n) {
        ans *= i;
        num = 0;
      }
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  ll n, p, ans = 1;
  cin >> n >> p;

  if (n == 1) {
    cout << p << endl;
    return 0;
  }
  for (ll i = 2; i * i <= p; i++) {
    ll num = 0;
    while (p % i == 0) {
      p /= i;
      num++;
      if (num == n) {
        ans *= i;
        num = 0;
      }
    }
  }
  cout << ans << endl;
}
Problem p03196 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  ll n, p;
  cin >> n >> p;
  ll r = 1;
  if (n < 40) {
    for (int i = 1; i <= p; i++) {
      ll x = pow(i, n);
      if (x > p) {
        break;
      }
      if (p % x == 0) {
        r = i;
      }
    }
  }
  cout << r << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  ll n, p;
  cin >> n >> p;
  ll r = 1;
  if (n == 1) {
    r = p;
  } else if (n < 40) {
    for (int i = 1; i <= p; i++) {
      ll x = pow(i, n);
      if (x > p) {
        break;
      }
      if (p % x == 0) {
        r = i;
      }
    }
  }
  cout << r << endl;
}
Problem p03196 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll qpow(ll a, ll n) {
  ll ret = 1;
  while (n) {
    if (n & 1)
      ret = ret * a;
    a = a * a;
    n >>= 1;
    if (ret > 1e12)
      return LLONG_MAX;
  }
  return ret;
}
int main() {
  ll n, p;
  cin >> n >> p;
  if (n > 40) {
    puts("1");
    return 0;
  }
  if (n == 1) {
    cout << p;
    return 0;
  }
  if (p == 1) {
    puts("1");
    return 0;
  }
  bool isp = 1;
  ll yz;
  for (ll i = 2; i * i <= p; i++) {
    if (p % i == 0) {
      isp = 0;
      yz = i;
      break;
    }
  }
  if (isp) {
    if (n == 1)
      cout << p;
    else
      puts("1");
    return 0;
  } else {
    ll ans = 1;
    for (ll i = 2; i * i <= p; i++) {
      if (p % i == 0) {
        ll in = qpow(i, n);
        if (p % in == 0) {
          ans = i;
        }
      }
    }
    cout << ans;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll qpow(ll a, ll n) {
  ll ret = 1;
  while (n) {
    if (n & 1)
      ret = ret * a;
    a = a * a;
    n >>= 1;
    if (ret > 1e12)
      return LLONG_MAX;
  }
  return ret;
}
int main() {
  ll n, p;
  cin >> n >> p;
  if (n > 40) {
    puts("1");
    return 0;
  }
  if (n == 1) {
    cout << p;
    return 0;
  }
  if (p == 1) {
    puts("1");
    return 0;
  }
  bool isp = 1;
  ll yz;
  for (ll i = 2; i * i <= p; i++) {
    if (p % i == 0) {
      isp = 0;
      yz = i;
      break;
    }
  }
  if (isp) {
    if (n == 1)
      cout << p;
    else
      puts("1");
    return 0;
  } else {
    ll ans = 1;
    for (ll i = 2; i * i <= p; i++) {
      if (p % i == 0) {
        ll in = qpow(i, n);
        while (p % in == 0) {
          p /= in;
          ans *= i;
        }
      }
    }
    cout << ans;
  }
  return 0;
}