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

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


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

Buggy submission (status: Time Limit Exceeded):
/*
ID: anonymo14
TASK: wormhole
LANG: C++
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i, a, b) for (int i = a; i <= b; i++)

#define MOD 1000000007

void solve(int test_case) { // 222
  ll n, p;
  cin >> n >> p;
  if (n > 40 || p == 1) {
    cout << 1;
    return;
  }
  ll mx = 1;
  for (ll i = 1; i <= p; i++) {
    ll val = pow(i, n);
    if (val > p || val < 0)
      break;
    if (p % val == 0) {
      mx = i;
    }
  }
  cout << mx;
}

int main() {

  ////// FILE BASED IO////
  // freopen("wormhole.in", "r", stdin);
  // freopen("wormhole.out", "w", stdout);
  ///////////////

  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  // cin>>t;
  REP(i, 1, t) { solve(i); }
  return 0;
}


Fixed submission:
/*
ID: anonymo14
TASK: wormhole
LANG: C++
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i, a, b) for (int i = a; i <= b; i++)

#define MOD 1000000007

void solve(int test_case) { // 222
  ll n, p;
  cin >> n >> p;
  if (n > 40 || p == 1) {
    cout << 1;
    return;
  }
  if (n == 1) {
    cout << p;
    return;
  }
  ll mx = 1;
  for (ll i = 1; i <= p; i++) {
    ll val = pow(i, n);
    if (val > p || val < 0)
      break;
    if (p % val == 0) {
      mx = i;
    }
  }
  cout << mx;
}

int main() {

  ////// FILE BASED IO////
  // freopen("wormhole.in", "r", stdin);
  // freopen("wormhole.out", "w", stdout);
  ///////////////

  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  // cin>>t;
  REP(i, 1, t) { solve(i); }
  return 0;
}
Problem p03194 (C++)

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

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll n, k;
  cin >> n >> k;
  if (n == 1) {
    cout << k;
    return 0;
  }
  if (n > 1000000) {
    cout << 1;
    return 0;
  }
  double c = 1;
  for (double i = 1;; i++) {
    if (k % (ll)pow(i, (double)n) == 0) {
      c = i;
    }
    if (k < (ll)pow(i, (double)n))
      break;
  }
  cout << (ll)c;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

template <typename T> map<T, T> prime_factor(T n) {
  map<T, T> res;

  for (int i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }

  if (n != 1)
    res[n] = 1;

  return res;
}

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

  auto prf = prime_factor(p);

  ll ans = 1LL;
  for (auto x : prf) {
    if (x.second >= n) {
      ans *= (ll)pow(x.first, x.second / n);
    }
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

template <typename T> map<T, T> prime_factor(T n) {
  map<T, T> res;

  for (T i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }

  if (n != 1)
    res[n] = 1;

  return res;
}

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

  auto prf = prime_factor(p);

  ll ans = 1LL;
  for (auto x : prf) {
    if (x.second >= n) {
      ans *= (ll)pow(x.first, x.second / n);
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;

int main() {
  long long int n, p, ans = 1;
  cin >> n >> p;
  long long int i = 1;
  long long int a = pow(2, n);
  long long int min = 2;
  int l = 2;
  while (pow(i, n) <= p) {
    long long int tmp = pow(i, n);
    if (p % tmp == 0) {
      ans *= i;
      p /= tmp;
      if (i == 1)
        i++;
    } else {
      if (i == 3)
        i += 2;
      else if (i > 4) {
        i += l;
        l = 6 - l;
      } else
        i++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  long long int n, p, ans = 1;
  cin >> n >> p;
  long long int i = 1;
  long long int a = pow(2, n);
  long long int min = 2;
  int l = 2;
  if (n == 1) {
    cout << p << endl;
    return 0;
  }
  while (pow(i, n) <= p) {
    long long int tmp = pow(i, n);
    if (p % tmp == 0) {
      ans *= i;
      p /= tmp;
      if (i == 1)
        i++;
    } else {
      if (i == 3)
        i += 2;
      else if (i > 4) {
        i += l;
        l = 6 - l;
      } else
        i++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <math.h>

using namespace std;

int main(void) {

  long long N, P;
  cin >> N;
  cin >> P;

  long long ans = 1;
  int i;

  if (N == 1) {
    ans = P;
  } else {
    for (i = 1; i < 100000000; i++) {
      long long kn = pow(i, N);
      if ((P % kn) == 0) {
        ans = i;
      }
      if (P < kn) {
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <iostream>
#include <math.h>

using namespace std;

int main(void) {

  long long N, P;
  cin >> N;
  cin >> P;

  long long ans = 1;
  int i;

  if (N == 1) {
    ans = P;
  } else {
    for (i = 2; i <= 1000010; i++) {
      long long kn = pow(i, N);
      if ((P % kn) == 0) {
        ans = i;
      }
      if (P < kn) {
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
/// @file

#include <cmath>
#include <iostream>

namespace {

bool run(std::istream &is, std::ostream &os);
} // unnamed namespace

/// @brief エントリポイント
#ifdef _TEST
static int run()
#else
int main()
#endif
{
  try {
    if (run(std::cin, std::cout) == false) {
      std::cerr << "main funciton error.\n";
      return EXIT_FAILURE;
    }
  } catch (const std::exception &e) {
    std::cerr << "catch exception\n";
    std::cerr << e.what() << "\n";
    return EXIT_FAILURE;
  }

  return EXIT_SUCCESS;
}

namespace {

/// @brief 実行処理
bool run(std::istream &is, std::ostream &os) {
  typedef long Num_t;

  Num_t n;
  Num_t p;
  is >> n >> p;

  // n 乗したときに p を超えない最大数を求める
  Num_t maxNum(1);
  for (; std::pow(maxNum, n) <= p; ++maxNum)
    ;
  --maxNum;

  // 最大数から逆側にあまりがなくなる値を求める
  Num_t divisor(maxNum);
  for (; divisor > 0; --divisor) {
    if (p % static_cast<Num_t>(std::pow(divisor, n)) == 0)
      break;
  }

  os << divisor << '\n';

  return true;
}
} // unnamed namespace


Fixed submission:
/// @file

#include <cmath>
#include <iostream>

namespace {

bool run(std::istream &is, std::ostream &os);
} // unnamed namespace

/// @brief エントリポイント
#ifdef _TEST
static int run()
#else
int main()
#endif
{
  try {
    if (run(std::cin, std::cout) == false) {
      std::cerr << "main funciton error.\n";
      return EXIT_FAILURE;
    }
  } catch (const std::exception &e) {
    std::cerr << "catch exception\n";
    std::cerr << e.what() << "\n";
    return EXIT_FAILURE;
  }

  return EXIT_SUCCESS;
}

namespace {

/// @brief 実行処理
bool run(std::istream &is, std::ostream &os) {
  typedef long Num_t;

  Num_t n;
  Num_t p;
  is >> n >> p;

  // n 乗したときに p を超えない最大数を求める
  Num_t maxNum = static_cast<Num_t>(std::ceil(std::pow(p, 1.0 / n)));

  // 最大数から逆側にあまりがなくなる値を求める
  Num_t divisor(maxNum);
  for (; divisor > 0; --divisor) {
    if (p % static_cast<Num_t>(std::pow(divisor, n)) == 0)
      break;
  }

  os << divisor << '\n';

  return true;
}
} // unnamed namespace
Problem p03194 (C++)

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

// ライブラリ始まり

// 定数

// 円周率
const double PI = 3.1415926535897932384;

// 天井
const int INF = 1000000000;       // = 10^9
const ll LINF = 1000000000000000; // = 10^15

// ABC文字列
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC";
const string abc = "abcdefghijklmnopqrstuvwxyzabc";

// よくあるmodくん
const ll MOD = 1000000007; // = 10^9 + 7

// 関数

// ctoi
int ctoi(char c) {
  if (c == '0') {
    return 0;
  }
  if (c == '1') {
    return 1;
  }
  if (c == '2') {
    return 2;
  }
  if (c == '3') {
    return 3;
  }
  if (c == '4') {
    return 4;
  }
  if (c == '5') {
    return 5;
  }
  if (c == '6') {
    return 6;
  }
  if (c == '7') {
    return 7;
  }
  if (c == '8') {
    return 8;
  }
  if (c == '9') {
    return 9;
  }
  return -1;
}

// 素数判定
bool PN(int x) {
  if (x <= 1) {
    return false;
  }
  if (x == 2) {
    return true;
  }
  for (int i = 2; i < sqrt(x) + 1; i++) {
    if (x % i == 0) {
      return false;
    }
  }
  return true;
}

// ライブラリ終わり

int main() {
  ll N, P;
  cin >> N >> P;
  ll ans = 1;
  for (ll i = 1; i <= P; i++) {
    ll K = pow(i, N);
    if (K > P) {
      break;
    }
    if (P % K == 0) {
      ans = i;
    }
  }
  cout << ans << endl;
}

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

// ライブラリ始まり

// 定数

// 円周率
const double PI = 3.1415926535897932384;

// 天井
const int INF = 1000000000;       // = 10^9
const ll LINF = 1000000000000000; // = 10^15

// ABC文字列
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC";
const string abc = "abcdefghijklmnopqrstuvwxyzabc";

// よくあるmodくん
const ll MOD = 1000000007; // = 10^9 + 7

// 関数

// ctoi
int ctoi(char c) {
  if (c == '0') {
    return 0;
  }
  if (c == '1') {
    return 1;
  }
  if (c == '2') {
    return 2;
  }
  if (c == '3') {
    return 3;
  }
  if (c == '4') {
    return 4;
  }
  if (c == '5') {
    return 5;
  }
  if (c == '6') {
    return 6;
  }
  if (c == '7') {
    return 7;
  }
  if (c == '8') {
    return 8;
  }
  if (c == '9') {
    return 9;
  }
  return -1;
}

// 素数判定
bool PN(int x) {
  if (x <= 1) {
    return false;
  }
  if (x == 2) {
    return true;
  }
  for (int i = 2; i < sqrt(x) + 1; i++) {
    if (x % i == 0) {
      return false;
    }
  }
  return true;
}

// ライブラリ終わり

int main() {
  ll N, P;
  cin >> N >> P;
  ll ans = 1;
  if (N == 1) {
    ans = P;
  } else {
    for (ll i = 1; i <= sqrt(P) + 1; i++) {
      ll K = pow(i, N);
      if (K > P) {
        break;
      }
      if (P % K == 0) {
        ans = i;
      }
    }
  }
  cout << ans << endl;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  long long N, P;
  cin >> N >> P;
  long long temp;
  bool flg;
  for (long long i = pow(P, 1 / double(N)) + 1; i > 0; i--) {
    temp = P;
    flg = true;
    for (long long j = 0; j < N; j++) {
      if (temp % i == 0) {
        temp = temp / i;
      } else {
        flg = false;
        break;
      }
    }
    if (flg) {
      cout << i;
      break;
    }
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  long long N, P;
  cin >> N >> P;
  long long temp;
  bool flg;
  for (long long i = pow(P, 1 / double(N)) + 1; i > 0; i--) {
    temp = P;
    flg = true;
    if (i == 1) {
      cout << i;
      break;
    }
    for (long long j = 0; j < N; j++) {
      if (temp % i == 0) {
        temp = temp / i;
      } else {
        flg = false;
        break;
      }
    }
    if (flg) {
      cout << i;
      break;
    }
  }
  return 0;
}
Problem p03194 (C++)

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

signed main() {
  int N, P;
  cin >> N >> P;
  int ans = 1;
  for (int i = 1; pow(i, N) <= P; i++) {
    int j = pow(i, N);
    if (P % j == 0)
      ans = i;
  }
  cout << ans << endl;
}


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

signed main() {
  int N, P;
  cin >> N >> P;
  int ans = 1;
  if (N == 1) {
    cout << P << endl;
    return 0;
  }
  for (int i = 1; pow(i, N) <= P; i++) {
    int j = pow(i, N);
    if (P % j == 0)
      ans = i;
  }
  cout << ans << endl;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#define ll long long
using namespace std;
typedef unsigned long long ull;
int main(void) {
  // Your code here!
  ll n, p;
  cin >> n >> p;
  ll ans = 1;
  for (ll i = 2; i <= p; i++) {
    ll count = 0;
    while (p % i == 0) {
      count++;
      if (count == n) {
        count = 0;
        ans *= i;
      }
      p /= i;
    }
  }
  cout << ans;
}

Fixed submission:
#include <iostream>
#define ll long long
using namespace std;
typedef unsigned long long ull;
int main(void) {
  // Your code here!
  ll n, p;
  cin >> n >> p;
  ll ans = 1;
  for (ll i = 2; i * i <= p; i++) {
    if (n == 1) {
      ans = p;
      break;
    }
    ll count = 0;
    while (p % i == 0) {
      count++;
      if (count == n) {
        count = 0;
        ans *= i;
      }
      p /= i;
    }
  }
  cout << ans;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long
#define fort(i, n) for (int i = 1; i <= n; ++i)
#define pi pair<int, int>
#define vi vector<int>
#define pb push_back
#define sz size()
#define er erase
#define fr first
#define sc second
#define rc(x) return cout << x, 0
using namespace std;

ll n, p, d;

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

int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  cin >> n >> p;
  if (n == 1)
    rc(p);
  for (ll i = 1ll; i <= p; ++i) {
    if (power(i, n) <= p) {
      if (p % power(i, n) == 0)
        d = i;
    } else
      break;
  }
  cout << d;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define fort(i, n) for (int i = 1; i <= n; ++i)
#define pi pair<int, int>
#define vi vector<int>
#define pb push_back
#define sz size()
#define er erase
#define fr first
#define sc second
#define rc(x) return cout << x, 0
using namespace std;

ll n, p, d;

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

int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  cin >> n >> p;
  if (n == 1)
    rc(p);
  if (n > log2(p))
    rc(1);
  for (ll i = 1ll; i <= p; ++i) {
    if (power(i, n) <= p) {
      if (p % power(i, n) == 0)
        d = i;
    } else
      break;
  }
  cout << d;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <math.h>
using namespace std;

int main() {
  long long int n, p, ans;
  cin >> n >> p;

  ans = pow((long double)p, 1.0 / (long double)n) + 1;
  while (ans > 1) {
    long long int num = 1;
    long long int x = n;
    while (x > 0) {
      num *= ans;
      x--;
    }
    if (p % num == 0) {
      break;
    } else {
      ans--;
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <iostream>
#include <math.h>
using namespace std;

int main() {
  long long int n, p, ans;
  cin >> n >> p;

  ans = pow((long double)p, 1.0 / (long double)n) + 1;
  while (ans > 1) {
    if (p % (long long int)pow((long long int)ans, (long long int)n) == 0) {
      break;
    } else {
      ans--;
    }
  }
  cout << ans << endl;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cmath>
#include <cstdio>
int main() {
  long long int n, k, p = 1, ans = 1;
  scanf("%lld %lld", &k, &n);
  while (n > 1) {
    p++;
    if (n % p != 0) {
      continue;
    }
    long long int c = 0;
    while (n % p == 0) {
      n /= p;
      c++;
    }
    ans *= pow(p, c / k);
  }
  printf("%lld\n", ans);
}

Fixed submission:
#include <cmath>
#include <cstdio>
int main() {
  long long int n, k, p = 1, ans = 1;
  scanf("%lld %lld", &k, &n);
  if (k == 1) {
    printf("%lld\n", n);
    return 0;
  }
  while (n > 1 && p <= sqrt(n)) {
    p++;
    if (n % p != 0) {
      continue;
    }
    long long int c = 0;
    while (n % p == 0) {
      n /= p;
      c++;
    }
    ans *= pow(p, c / k);
  }
  printf("%lld\n", ans);
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;
#define M 1000000007

ll power(ll a, ll n) {
  ll ans = 1;
  while (0 < n) {
    if (n % 2 == 0) {
      a *= a;
      n >>= 1;
    } else {
      ans *= a;
      n--;
    }
  }
  return ans;
}

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

  if (n >= 40) {
    cout << 1 << endl;
    return 0;
  }

  for (int i = 2; power(i, n) <= p; i++) {
    while (p % power(i, n) == 0) {
      ans *= i;
      p /= power(i, n);
    }
  }
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;
#define M 1000000007

ll power(ll a, ll n) {
  ll ans = 1;
  while (0 < n) {
    if (n % 2 == 0) {
      a *= a;
      n >>= 1;
    } else {
      ans *= a;
      n--;
    }
  }
  return ans;
}

int main(void) {
  ll n, p, ans = 1;
  cin >> n >> p;
  if (n == 1) {
    cout << p << endl;
    return 0;
  }
  if (n >= 40) {
    cout << 1 << endl;
    return 0;
  }

  for (int i = 2; power(i, n) <= p; i++) {
    while (p % power(i, n) == 0) {
      ans *= i;
      p /= power(i, n);
    }
  }
  cout << ans << endl;

  return 0;
}
Problem p03194 (Python)

Buggy submission (status: Time Limit Exceeded):
N, P = list(map(int, input().split()))
if N == 1:
    print(P)
    exit()
elif P == 1:
    print("1")
    exit()

ans = 1
tmp = P

for i in range(2, P):
    po = pow(i, N)
    while tmp % po == 0:
        tmp = tmp // po
        ans = ans * i
        # print(i, tmp, ans)

    if tmp < po:
        break

print(ans)


Fixed submission:
N, P = list(map(int, input().split()))
if N == 1:
    print(P)
    exit()
elif P == 1:
    print("1")
    exit()

ans = 1
tmp = P

for i in range(2, int(pow(P, 1 / N)) + 1):
    po = pow(i, N)
    while tmp % po == 0:
        tmp = tmp // po
        ans = ans * i
        # print(i, tmp, ans)

    if tmp < po:
        break

print(ans)
Problem p03194 (Python)

Buggy submission (status: Time Limit Exceeded):
from collections import Counter


def d(P):
    c = Counter()
    i = 2
    while P > 1:
        if P % i == 0:
            c.update([i])
            P //= i
            i -= 1
        i += 1
    return c


def solve(N, P):
    c = d(P)
    ans = 1
    for k in [k for k, v in c.items() if v >= N]:
        ans *= k ** (c[k] // N)
    return ans


if __name__ == "__main__":
    N, X = tuple(map(int, input().split(" ")))
    print(solve(N, X))


Fixed submission:
from collections import Counter


def d(P):
    c = Counter()
    i = 2
    while P > 1:
        if P % i == 0:
            c.update([i])
            P //= i
            i -= 1
        i += 1
        if i > P**0.5:
            c.update([P])
            break
    return c


def solve(N, P):
    c = d(P)
    ans = 1
    for k in [k for k, v in c.items() if v >= N]:
        ans *= k ** (c[k] // N)
    return ans


if __name__ == "__main__":
    N, X = tuple(map(int, input().split(" ")))
    print(solve(N, X))
Problem p03194 (Python)

Buggy submission (status: Time Limit Exceeded):
n, p = map(int, input().split())

if n == 1:
    print(p)
else:
    m = 1
    while m**n <= p:
        m += 1
    for i in reversed(range(1, m + 1)):
        if p % (i**n) == 0:
            print(i)
            break


Fixed submission:
n, p = map(int, input().split())

if n == 1:
    print(p)
else:
    m = int((p + 1) ** (1 / n))
    while m**n > p:
        m -= 1
    for i in reversed(range(1, m + 1)):
        if p % (i**n) == 0:
            print(i)
            break
Problem p03194 (Python)

Buggy submission (status: Time Limit Exceeded):
import math

N, P = list(map(int, input().split()))

for i in range(int(math.pow(P, 1 / N)) + 1, 0, -1):
    if P % (i**N) == 0:
        print(i)
        break


Fixed submission:
n, p = map(int, input().split())
if n == 1:
    print(p)
else:
    for i in range(1, round(p ** (1 / n)) + 1):
        if p % i**n == 0:
            res = i
    print(res)
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <utility>
#include <vector>
using namespace std;
int main() {
  unsigned long n, p;
  cin >> n >> p;
  vector<pair<unsigned long, unsigned long>> factors;
  // prime factorize p
  for (unsigned long i = 2; i <= p; i++) {
    unsigned long j = 0;
    for (j = 0; p % i == 0; j++) {
      p = p / i;
    }
    if (j > 0) {
      factors.push_back({i, j});
    }
  }
  unsigned long max_factor = 1;
  for (pair<unsigned long, unsigned long> factor_pair : factors) {
    unsigned long factor = get<0>(factor_pair);
    unsigned long exp = get<1>(factor_pair);
    unsigned long mult = static_cast<unsigned long>(exp / n);
    unsigned long mult_factor = powl(factor, mult);
    if (exp >= n) {
      max_factor *= mult_factor;
    }
    //    printf("%lu %lu => %lu ^ %lu = %lu\n", factor, exp,
    //           factor, mult, mult_factor);
  }
  printf("%lu\n", max_factor);
  return 0;
}


Fixed submission:
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <utility>
#include <vector>
using namespace std;
int main() {
  unsigned long n, p;
  cin >> n >> p;
  vector<pair<unsigned long, unsigned long>> factors;
  // prime factorize p
  for (unsigned long i = 2; i <= p; i++) {
    unsigned long j = 0;
    if (i > sqrt(p)) {
      if (i < p) {
        factors.push_back({p, 1});
      }
      break;
    }
    for (j = 0; p % i == 0; j++) {
      p = p / i;
    }
    if (j > 0) {
      factors.push_back({i, j});
    }
  }
  unsigned long max_factor = 1;
  for (pair<unsigned long, unsigned long> factor_pair : factors) {
    unsigned long factor = get<0>(factor_pair);
    unsigned long exp = get<1>(factor_pair);
    unsigned long mult = static_cast<unsigned long>(exp / n);
    unsigned long mult_factor = powl(factor, mult);
    if (exp >= n) {
      max_factor *= mult_factor;
    }
    //    printf("%lu %lu => %lu ^ %lu = %lu\n", factor, exp,
    //           factor, mult, mult_factor);
  }
  printf("%lu\n", max_factor);
  return 0;
}
Problem p03194 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll f(ll x, ll res) {
  ll ans = 1;
  while (x) {
    if (x & 1)
      ans = ans * res;
    res *= res;
    x /= 2;
  }
  return ans;
}
int main() {
  ll n, p;
  ll ans = 1;
  cin >> n >> p;
  for (ll i = 2;; i++) {
    ll k = f(n, i);
    if (p < k)
      break;
    if (p % k == 0)
      ans = i;
  }
  printf("%lld\n", ans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll f(ll x, ll res) {
  ll ans = 1;
  while (x) {
    if (x & 1)
      ans = ans * res;
    res *= res;
    x /= 2;
  }
  return ans;
}
int main() {
  ll n, p;
  ll ans = 1;
  cin >> n >> p;
  if (n == 1) {
    cout << p;
    return 0;
  }
  if (p == 1) {
    cout << "1";
    return 0;
  }
  if (n >= p) {
    cout << "1";
    return 0;
  }
  if (n > 1000000) {
    cout << "1";
    return 0;
  }
  for (ll i = 2;; i++) {
    ll k = f(n, i);
    if (p < k)
      break;
    if (p % k == 0)
      ans = i;
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e6 + 7;
const int Inf = 1 << 30;
const ll INF = 1LL << 60;
#define mst(x) memset(x, 0, sizeof(x))
ll n, p;
ll pr[maxx]; // p的所有因子
map<ll, bool> vis;
ll ans;

int main() {
  vis.clear();
  cin >> n >> p;
  if (n == 1) {
    cout << p << endl;
    return 0;
  }
  int tot = 0;
  for (int i = 1; i <= sqrt(p); i++) {
    if (p % i == 0)
      pr[++tot] = i;
  }
  int dd;
  double tmp = sqrt(p);
  if (tmp == (int)tmp)
    dd = tot - 1;
  else
    dd = tot;
  for (int i = 1; i <= dd; i++)
    pr[++tot] = p / pr[i];
  sort(pr + 1, pr + tot + 1);

  // 如果除1以外的最小因子的n次幂都比p大, 那gcd必为1
  ll f = pr[2]; // 除1以外的最小因子
  ll m = 1;
  while (f * pr[2] <= p) {
    f *= pr[2];
    m++;
  }
  if (m < n) {
    puts("1");
    return 0;
  }

  for (int i = 1; i <= tot; i++)
    vis[pr[i]] = 1;
  bool chk = 0;
  for (int i = tot; i >= 2; i--) {
    ll pp = pr[i];
    ll cnt = 1;
    bool flg = 0;
    while (pp * pr[i] <= p) {
      pp *= pr[i];
      cnt++;
      if (cnt == n) {
        flg = 1;
        break;
      }
    }
    if (flg && vis[pp]) {
      chk = 1;
      ans = pr[i];
      break;
    }
  }
  if (!chk)
    puts("1");
  else
    cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e6 + 7;
const int Inf = 1 << 30;
const ll INF = 1LL << 60;
#define mst(x) memset(x, 0, sizeof(x))
ll n, p;
ll pr[maxx]; // p的所有因子
map<ll, bool> vis;
ll ans;

int main() {
  vis.clear();
  cin >> n >> p;
  if (n == 1) {
    cout << p << endl;
    return 0;
  }
  int tot = 0;
  for (int i = 1; i <= sqrt(p); i++) {
    if (p % i == 0)
      pr[++tot] = i;
  }
  int dd;
  double tmp = sqrt(p);
  if (tmp == (int)tmp)
    dd = tot - 1;
  else
    dd = tot;
  for (int i = 1; i <= dd; i++)
    pr[++tot] = p / pr[i];
  sort(pr + 1, pr + tot + 1);

  /* 如果除1以外的最小因子的n次幂都比p大, 那gcd必为1 */
  if (tot > 1) {
    ll f = pr[2]; // 除1以外的最小因子
    ll m = 1;
    while (f * pr[2] <= p) {
      f *= pr[2];
      m++;
    }
    if (m < n) {
      puts("1");
      return 0;
    }
  }

  for (int i = 1; i <= tot; i++)
    vis[pr[i]] = 1;
  bool chk = 0;
  for (int i = tot; i >= 2; i--) {
    ll pp = pr[i];
    ll cnt = 1;
    bool flg = 0;
    while (pp * pr[i] <= p) {
      pp *= pr[i];
      cnt++;
      if (cnt == n) {
        flg = 1;
        break;
      }
    }
    if (flg && vis[pp]) {
      chk = 1;
      ans = pr[i];
      break;
    }
  }
  if (!chk)
    puts("1");
  else
    cout << ans << endl;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <math.h>
using namespace std;
int main(void) {
  long ans = 0;
  long long n = 0, i, N, P;
  cin >> N >> P;
  for (i = 1; n < P && n >= 0; i++) {
    n = powl(i, N);
    //		cout<<n<<" "<<i<<" "<<P<<" "<<ans<<endl;
    if (P % n == 0)
      ans = i;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <iostream>
#include <math.h>
using namespace std;
int main(void) {
  long ans = 0;
  long long n = 0, i, N, P;
  cin >> N >> P;
  if (N == 1) {
    cout << P << endl;
    return 0;
  }
  for (i = 1; n < P && n >= 0; i++) {
    n = powl(i, N);
    //		cout<<n<<" "<<i<<" "<<P<<" "<<ans<<endl;
    if (P % n == 0)
      ans = i;
  }
  cout << ans << endl;
  return 0;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <unordered_set>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
unordered_multiset<long long int> fact(long long int n) {
  unordered_multiset<long long int> ret;
  long long int a = 2;
  while (n != 1) {
    if (n % a == 0) {
      n /= a;
      ret.insert(a--);
    }
    a++;
  }
  return ret;
}
int main() {
  long long int n, p;
  cin >> n >> p;
  if (n == 1) {
    cout << p;
    return 0;
  }
  if (n >= 40) {
    cout << "1" << endl;
    return 0;
  }
  long long int ans = 1;
  auto l = fact(p);
  long long int cnt = 0;
  for (long long int i = 1; p >= pow(i - 1, n); ++i)
    cnt = i;
  rep(i, cnt) {
    long long int tmp = l.count(i);
    if (tmp >= n)
      ans *= pow(i, tmp / n);
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <unordered_set>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
unordered_multiset<long long int> fact(long long int n) {
  unordered_multiset<long long int> ret;
  long long int a = 2;
  while (n != 1) {
    if (n % a == 0) {
      n /= a;
      ret.insert(a--);
    }
    a++;
  }
  return ret;
}
int main() {
  long long int n, p;
  cin >> n >> p;
  if (n == 1) {
    cout << p;
    return 0;
  }
  if (n >= 40 || n == 16) {
    cout << "1" << endl;
    return 0;
  }
  long long int ans = 1;
  auto l = fact(p);
  long long int cnt = 0;
  for (long long int i = 1; p >= pow(i - 1, n); ++i)
    cnt = i;
  rep(i, cnt) {
    long long int tmp = l.count(i);
    if (tmp >= n)
      ans *= pow(i, tmp / n);
  }
  cout << ans << endl;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define dum(x) cout << #x << '=' << x << endl
#define ll long long
using namespace std;

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

  ll ans = 1;
  for (int i = 2; i * i <= p; i++) {
    int cnt = 0;
    while (p % i == 0) {
      cnt++;
      p /= i;
    }

    int tmp = cnt / n;
    for (int j = 0; j < tmp; j++) {
      ans *= i;
    }
  }
  if (n == 1)
    ans *= p;
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define dum(x) cout << #x << '=' << x << endl
#define ll long long
using namespace std;

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

  ll ans = 1;
  for (ll i = 2; i * i <= p; i++) {
    int cnt = 0;
    while (p % i == 0) {
      cnt++;
      p /= i;
    }

    int tmp = cnt / n;
    for (int j = 0; j < tmp; j++) {
      ans *= i;
    }
  }
  if (n == 1)
    ans *= p;
  cout << ans << endl;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <math.h>
#include <set>
#include <string>
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  long N, P, i, k, j, a, s;
  cin >> N >> P;
  s = (long)pow((double)(P), 1.0 / (double)(N));
  a = 0;
  for (i = 1; i <= s + 1; i++) {
    j = (long)pow((double)(i), (double)(N));
    if (P % j == 0)
      a = i;
    if (P <= j)
      break;
  }

  cout << a;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <math.h>
#include <set>
#include <string>
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  long N, P, i, k, j, a, s;
  cin >> N >> P;
  s = (long)pow((double)(P), 1.0 / (double)(N));
  a = 0;
  if (N == 1)
    a = P;
  else {

    for (i = 1; i <= s + 1; i++) {
      j = (long)pow((double)(i), (double)(N));
      if (P % j == 0)
        a = i;
      if (P <= j)
        break;
    }
  }

  cout << a;
  return 0;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <regex>
#include <stack>
#include <string>
#include <utility>
#include <vector>

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

using namespace std;

typedef long long ll;

int main(int argc, char const *argv[]) {
  ll n, p;
  cin >> n >> p;
  ll radicand = 1;
  ll ans = 1;
  while (pow(radicand, n) <= p) {
    if (p % (ll)pow(radicand, n) == 0)
      ans = radicand;
    radicand++;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <regex>
#include <stack>
#include <string>
#include <utility>
#include <vector>

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

using namespace std;

typedef long long ll;

int main(int argc, char const *argv[]) {
  ll n, p;
  cin >> n >> p;
  ll radicand = 1;
  ll ans = 1;
  if (n == 1) {
    cout << p << endl;
    return 0;
  }
  while (pow(radicand, n) <= p) {
    if (p % (ll)pow(radicand, n) == 0)
      ans = radicand;
    radicand++;
  }
  cout << ans << endl;
  return 0;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, num, verysum = 1;
  cin >> n >> num;
  if (n >= 40) {
    cout << 1;
    return 0;
  }
  for (int i = 2; i <= num; i++) {
    long long t = num;
    while (t % int(pow(i, n)) == 0)
      verysum *= i, t /= (pow(i, n));
    num = t;
  }
  cout << verysum;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, num, verysum = 1;
  cin >> n >> num;
  if (n >= 40) {
    cout << 1;
    return 0;
  }
  if (n == 1) {
    cout << num;
    return 0;
  }
  for (int i = 2; pow(i, n) <= num; i++) {
    while (num % (long long)(pow(i, n)) == 0)
      verysum *= i, num /= (pow(i, n));
  }
  cout << verysum;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

int main() {
  long N, P;
  cin >> N;
  cin >> P;
  long zantei = 1;
  long temp;
  if (N == 1) {
    zantei = P;
  } else if (P == 1) {

  } else {
    for (long i = 2; i <= P; i++) {
      temp = pow(i, N);

      if (temp > P) {
        break;
      }
      if (P % temp == 0) {
        zantei = i;
      }
    }
  }

  cout << zantei << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

int main() {
  long N, P;
  cin >> N;
  cin >> P;
  long zantei = 1;
  long temp;
  if (N == 1) {
    zantei = P;
  } else if (P == 1 || N > 39) {

  } else {
    for (long i = 2; i <= P; i++) {
      temp = pow(i, N);

      if (temp > P) {
        break;
      }
      if (P % temp == 0) {
        zantei = i;
      }
    }
  }

  cout << zantei << endl;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
  ll N, P, ans = 1;
  cin >> N >> P;
  for (ll i = 2; pow(i, N) <= P; i++) {
    ll tmp = pow(i, N);
    if (P % tmp == 0)
      ans = i;
  }
  printf("%lld\n", ans);
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
  ll N, P, ans = 1;
  cin >> N >> P;
  if (N == 1) {
    printf("%lld\n", P);
    return 0;
  }
  for (ll i = 2; pow(i, N) <= P; i++) {
    ll tmp = pow(i, N);
    if (P % tmp == 0)
      ans = i;
  }
  printf("%lld\n", ans);
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a, n) vector<int>(a)((n))
#define Vec(a, n) vector<string>(a)((n))
#define P pair<int, int>
#define PQ(n) priority_queue<P, vector<P>, greater<P>>(n)
#define pq(n) priority_queue<int>(n)
using namespace std;

signed main() {
  int n, p, ans = 1;
  cin >> n >> p;
  if (n == 1) {
    cout << p << endl;
    return 0;
  }
  int temp = p;
  for (int i = 2; p >= i * i; i++) {
    int tmp = temp;
    int x = 1, cnt = 0;

    while (x == 1) {
      if (tmp % i != 0) {
        x = 0;
      } else {
        cnt++;
        tmp /= i;
      }
    }
    REP(j, cnt / n) {
      ans *= i;
      REP(k, cnt / n) { temp /= i; }
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a, n) vector<int>(a)((n))
#define Vec(a, n) vector<string>(a)((n))
#define P pair<int, int>
#define PQ(n) priority_queue<P, vector<P>, greater<P>>(n)
#define pq(n) priority_queue<int>(n)
using namespace std;

signed main() {
  int n, p, ans = 1;
  cin >> n >> p;
  if (n == 1) {
    cout << p << endl;
    return 0;
  }
  int temp = p;
  for (int i = 2; p >= i * i; i++) {
    int tmp = temp;
    int x = 1, cnt = 0;

    while (x == 1) {
      if (tmp % i != 0) {
        x = 0;
      } else {
        cnt++;
        tmp /= i;
      }
    }
    int temp1 = 1;
    REP(j, cnt / n) { temp1 *= i; }
    if (temp1 != 1) {
      ans *= temp1;
      REP(k, n) { temp /= temp1; }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <map>
using namespace std;
typedef long long int ll;

map<ll, ll> M;

ll N, P, ans = 1;

void disassemble(ll p) {
  for (int i = 2; i * i <= p; i++) {
    ll cnt = 0;
    while (p % i == 0) {
      cnt++;
      p /= i;
      if (cnt == N) {
        ans *= i;
        cnt = 0;
      }
    }
  }
}

int main() {
  cin >> N >> P;
  disassemble(P);
  if (N == 1) {
    cout << P << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
#include <map>
using namespace std;
typedef long long int ll;

map<ll, ll> M;

ll N, P, ans = 1;

void disassemble(ll p) {
  for (ll i = 2; i * i <= p; i++) {
    ll cnt = 0;
    while (p % i == 0) {
      cnt++;
      p /= i;
      if (cnt == N) {
        ans *= i;
        cnt = 0;
      }
    }
  }
}

int main() {
  cin >> N >> P;
  disassemble(P);
  if (N == 1) {
    cout << P << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <map>
using namespace std;

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

long long mod_pow(long long x, long long n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * x;
    x = x * x;
    n >>= 1;
  }
  return res;
}

int main() {
  long long N, P;
  cin >> N >> P;
  map<long, long> mp = prime_factor(P);
  long long ans = 1;
  for (auto it = mp.begin(); it != mp.end(); ++it) {
    if (it->second >= N)
      ans *= mod_pow(it->first, it->second / N);
  }
  cout << ans << endl;
}


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

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

long long mod_pow(long long x, long long n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * x;
    x = x * x;
    n >>= 1;
  }
  return res;
}

int main() {
  long long N, P;
  cin >> N >> P;
  map<long, long> mp = prime_factor(P);
  long long ans = 1;
  for (auto it = mp.begin(); it != mp.end(); ++it) {
    if (it->second >= N)
      ans *= mod_pow(it->first, it->second / N);
  }
  cout << ans << endl;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
#define ll long long int

int main(int argc, const char *argv[]) {
  ll N, P;
  cin >> N >> P;
  if (N == 1) {
    cout << P << endl;
    return 0;
  }
  //	int max = (int)sqrt(P)+1;
  ll max = P / 2;
  ll ret = 1;
  for (ll divider = 2; divider <= max && P != 1; ++divider) {
    ll count = 0;
    while (P % divider == 0) {
      //			cerr << divider;
      count++;
      P /= divider;
    }
    if (count > 0) {
      //			cerr << divider << "**" << count << endl;
    }
    while (count >= N) {
      //			cerr << divider << endl;
      ret *= divider;
      count -= N;
    }
  }
  cout << ret << endl;
}


Fixed submission:
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
#define ll long long int

int main(int argc, const char *argv[]) {
  ll N, P;
  cin >> N >> P;
  if (N == 1) {
    cout << P << endl;
    return 0;
  }
  ll max = (int)pow(1.0 * P, 1.0 / N);
  ll ret = 1;
  for (ll divider = 2; divider <= max && P != 1; ++divider) {
    ll count = 0;
    while (P % divider == 0) {
      //			cerr << divider;
      count++;
      P /= divider;
    }
    if (count > 0) {
      //			cerr << divider << "**" << count << endl;
    }
    while (count >= N) {
      //			cerr << divider << endl;
      ret *= divider;
      count -= N;
    }
  }
  cout << ret << endl;
}
Problem p03194 (C++)

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

int main() {
  string s;

  long long ans = 1, n, a;
  cin >> n >> a;
  for (long long i = 2; i <= a; i++) {

    if (a % i == 0) {
      int cnt = 0;
      while (a % i == 0) {
        cnt++;
        a /= i;
      }
      cnt /= n;
      for (int j = 0; j < cnt; j++)
        ans *= i;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  string s;

  long long ans = 1, n, a;
  cin >> n >> a;
  if (n == 1) {
    cout << a << endl;
    return 0;
  }
  for (long long i = 2; i <= sqrt(a) + 1; i++) {

    if (a % i == 0) {
      int cnt = 0;
      while (a % i == 0) {
        cnt++;
        a /= i;
      }
      cnt /= n;
      for (int j = 0; j < cnt; j++)
        ans *= i;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <map>
using namespace std;
long long n, p, cnt;
map<long long, int> v;
int main() {
  cin >> n >> p;
  for (int i = 2; i * i <= p; i++)
    while (p % i == 0)
      v[i]++, p /= i, cnt++;
  if (p > 1)
    v[p]++;
  long long res = 1;
  for (map<long long, int>::iterator it = v.begin(); it != v.end(); it++)
    for (int i = 0; i < (*it).second / n; i++)
      res *= it->first;
  cout << res;
}


Fixed submission:
#include <iostream>
#include <map>
using namespace std;
long long n, p, cnt;
map<long long, int> v;
int main() {
  cin >> n >> p;
  for (int i = 2; i * 1ll * i <= p; i++)
    while (p % i == 0)
      v[i]++, p /= i, cnt++;
  if (p > 1)
    v[p]++;
  long long res = 1;
  for (map<long long, int>::iterator it = v.begin(); it != v.end(); it++)
    for (int i = 0; i < (*it).second / n; i++)
      res *= it->first;
  cout << res;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef long long int llt;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, p;
  cin >> n >> p;
  if (p == 1)
    cout << 1 << endl;
  else {
    ll ans = 1;
    for (ll i = 2; i <= p; i++) {
      ll tmp = pow(i, n);
      if (tmp <= p && p % tmp == 0) {
        ans = max(ans, i);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef long long int llt;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, p;
  cin >> n >> p;
  if (p == 1)
    cout << 1 << endl;
  else {

    ll ans = 1, yj = sqrt(p);
    if (n == 1)
      ans = p;
    else {
      for (ll i = 2; i <= yj; i++) {
        ll tmp = pow(i, n);
        if (tmp <= p && p % tmp == 0) {
          ans = max(ans, i);
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
int main() {
  ll N, P;
  cin >> N >> P;
  ll tmp = 2;
  ll cnt;
  ll ans = 1;
  if (N == 1) {
    cout << P;
  } else {
    cnt = 0;
    while (P % tmp == 0) {
      P = P / tmp;
      cnt++;
    }
    ans *= pow(tmp, cnt / N);
    tmp = 3;
    while (tmp < P) {
      cnt = 0;
      while (P % tmp == 0) {
        P = P / tmp;
        cnt++;
      }
      ans *= pow(tmp, cnt / N);
      tmp += 2;
    }
    cout << ans;
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
int main() {
  ll N, P;
  cin >> N >> P;
  ll tmp = 2;
  ll cnt;
  ll ans = 1;
  if (N == 1) {
    cout << P;
  } else {
    cnt = 0;
    while (P % tmp == 0) {
      P = P / tmp;
      cnt++;
    }
    ans *= pow(tmp, cnt / N);
    tmp = 3;
    while (tmp * tmp <= P) {
      cnt = 0;
      while (P % tmp == 0) {
        P = P / tmp;
        cnt++;
      }
      ans *= pow(tmp, cnt / N);
      tmp += 2;
    }
    cout << ans;
  }
  return 0;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <map>
using namespace std;
typedef long long ll;

int main() {
  ll n, p;
  map<ll, ll> yakusuu;
  cin >> n >> p;
  while (p % 2 == 0) {
    yakusuu[2]++;
    p /= 2;
  }
  for (int i = 3; i * i <= p; i += 2) {
    while (p % i == 0) {
      yakusuu[i]++;
      p /= i;
    }
  }
  yakusuu[p]++;
  ll ans = 1;
  for (auto itr = yakusuu.begin(); itr != yakusuu.end(); itr++) {
    ll x = itr->second / n;
    while (x--)
      ans *= itr->first;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <iostream>
#include <map>
using namespace std;
typedef long long ll;

int main() {
  ll n, p;
  map<ll, ll> yakusuu;
  cin >> n >> p;
  while (p % 2 == 0) {
    yakusuu[2]++;
    p /= 2;
  }
  for (ll i = 3; i * i <= p; i += 2) {
    while (p % i == 0) {
      yakusuu[i]++;
      p /= i;
    }
  }
  yakusuu[p]++;
  ll ans = 1;
  for (auto itr = yakusuu.begin(); itr != yakusuu.end(); itr++) {
    ll x = itr->second / n;
    while (x--)
      ans *= itr->first;
  }
  cout << ans << endl;
  return 0;
}