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

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

using namespace std;

typedef long long ll;
const ll INF = 1LL << 60;

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

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll A, B;
  cin >> A >> B;

  ll gcdAB = gcd(A, B);
  set<ll> st;

  ll tmp = gcdAB;

  for (int i = 2; i * i < gcdAB; i++) {
    while (tmp % i == 0) {
      tmp = tmp / i;
      st.insert(i);
    }
    if (tmp == 1) {
      break;
    }
  }
  if (tmp > 1) {
    st.insert(gcdAB);
  }

  cout << (st.size() + 1) << endl;

  // for(auto itr = st.begin(); itr != st.end(); itr++){
  //   cout << *itr << endl;
  // }

  // for(auto itr = sB.begin(); itr != sB.end(); itr++){
  //   cout << *itr << endl;
  // }

  return 0;
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL << 60;

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

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll A, B;
  cin >> A >> B;

  ll gcdAB = gcd(A, B);
  set<ll> st;

  ll tmp = gcdAB;

  for (ll i = 2; i * i < gcdAB; i++) {
    while (tmp % i == 0) {
      tmp = tmp / i;
      st.insert(i);
    }
    if (tmp == 1) {
      break;
    }
  }
  if (tmp > 1) {
    st.insert(gcdAB);
  }

  cout << (st.size() + 1) << endl;

  // for(auto itr = st.begin(); itr != st.end(); itr++){
  //   cout << *itr << endl;
  // }

  // for(auto itr = sB.begin(); itr != sB.end(); itr++){
  //   cout << *itr << endl;
  // }

  return 0;
}
Problem p02900 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define be(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define doublecout(a) cout << fixed << setprecision(10) << a << endl;
typedef long long ll;
using namespace std;
const ll mod = 998244353;
template <class T> inline T lcm(T a, T b) { return (a * b / __gcd(a, b)); }

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a, b;
  cin >> a >> b;
  ll g = __gcd(a, b);
  ll ans = 1;
  for (int i = 2; i * i <= g; i++) {
    if (g % i == 0) {
      ans++;
      while (g % i == 0) {
        g /= i;
      }
    }
  }
  if (g != 1) {
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define be(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define doublecout(a) cout << fixed << setprecision(10) << a << endl;
typedef long long ll;
using namespace std;
const ll mod = 998244353;
template <class T> inline T lcm(T a, T b) { return (a * b / __gcd(a, b)); }

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a, b;
  cin >> a >> b;
  ll g = __gcd(a, b);
  ll ans = 1;
  for (ll i = 2; i * i <= g; i++) {
    if (g % i == 0) {
      ans++;
      while (g % i == 0) {
        g /= i;
      }
    }
  }
  if (g != 1) {
    ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02900 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <stdio.h>
#include <tuple>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

ll GCD(ll a, ll b) {
  if (a < b)
    swap(a, b);
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
ll a, b;
int main() {
  scanf("%lld %lld", &a, &b);
  ll G = GCD(a, b), d = G;
  int count = 1;
  for (int i = 2; i * i <= G && d != 1; i++) {
    if (d % i)
      continue;
    count++;
    while (!(d % i))
      d /= i;
  }
  count += d != 1;
  printf("%d\n", count);
}

Fixed submission:
#include <algorithm>
#include <stdio.h>
#include <tuple>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

ll GCD(ll a, ll b) {
  if (a < b)
    swap(a, b);
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
ll a, b;
int main() {
  scanf("%lld %lld", &a, &b);
  ll G = GCD(a, b), d = G;
  int count = 1;
  for (ll i = 2; i * i <= G && d != 1; i++) {
    if (d % i)
      continue;
    count++;
    while (!(d % i))
      d /= i;
  }
  count += d != 1;
  printf("%d\n", count);
}
Problem p02900 (C++)

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

using namespace std;

long long gcd(long long a, long long b) {
  if (b == 0)
    return a;

  return (gcd(b, a % b));
}

int main() {
  long long a, b, g, ans;
  cin >> a >> b;
  g = gcd(a, b);
  map<int, int> mp;
  for (int i = 2; i * i <= g; i++) {
    if (g == 1)
      break;
    while (g % i == 0) {
      g = g / i;
      mp[i]++;
    }
  }
  if (g != 1)
    mp[g]++;
  ans = mp.size() + 1;
  cout << ans << endl;
  return 0;
}


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

using namespace std;

long long gcd(long long a, long long b) {
  if (b == 0)
    return a;

  return (gcd(b, a % b));
}

int main() {
  long long a, b, g, ans;
  cin >> a >> b;
  g = gcd(a, b);
  map<int, int> mp;
  for (long long i = 2; i * i <= g; i++) {
    if (g == 1)
      break;
    while (g % i == 0) {
      g = g / i;
      mp[i]++;
    }
  }
  if (g != 1)
    mp[g]++;
  ans = mp.size() + 1;
  cout << ans << endl;
  return 0;
}
Problem p02900 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int a, b, c, i, ans;

int main() {
  cin >> a >> b;
  c = __gcd(a, b);
  for (i = 2; i * i <= c; ++i) {
    if (c % i == 0) {
      ++ans;
      while (c % i == 0) {
        c /= i;
      }
    }
  }

  if (c != 1) {
    ++ans;
  }
  cout << ans + 1;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
long a, b, c, i, ans;

int main() {
  cin >> a >> b;
  c = __gcd(a, b);
  for (i = 2; i * i <= c; ++i) {
    if (c % i == 0) {
      ++ans;
      while (c % i == 0) {
        c /= i;
      }
    }
  }

  if (c != 1) {
    ++ans;
  }
  cout << ans + 1;
}
Problem p02900 (C++)

Buggy submission (status: Runtime Error):
/* while(!cin.eof()) */

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod (int)(1e9 + 7)
#define MAXI (int)(1e15 + 100)
#define N 1000500

// Driver code to test above functions
int32_t main() {

#ifndef ONLINE_JUDGE
  // for getting input from inpu.txt
  freopen("input.txt", "r", stdin);
// for writing output to output.txt
// freopen("output.txt", "w", stdout);
#endif

  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);

  int n, m;
  cin >> n >> m;
  n = __gcd(n, m);

  int ans = 1;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      ans++;
      while (n % i == 0)
        n /= i;
    }
  }

  if (n != 1)
    ans++;

  cout << ans;

  return 0;
}

Fixed submission:
/* while(!cin.eof()) */

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod (int)(1e9 + 7)
#define MAXI (int)(1e15 + 100)
#define N 1000500

// Driver code to test above functions
int32_t main() {

  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);

  int n, m;
  cin >> n >> m;
  n = __gcd(n, m);

  int ans = 1;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      ans++;
      while (n % i == 0)
        n /= i;
    }
  }

  if (n != 1)
    ans++;

  cout << ans;

  return 0;
}
Problem p02900 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(x) cerr << #x << ": " << x << '\n';
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a, b, n, cnt = 1;
  cin >> a >> b;
  n = __gcd(a, b);
  for (int i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      cnt++;
      while (n % i == 0) {
        n /= i;
      }
    }
  }
  if (n != 1)
    cnt++;
  cout << cnt << '\n';
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(x) cerr << #x << ": " << x << '\n';
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a, b, n, cnt = 1;
  cin >> a >> b;
  n = __gcd(a, b);
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      cnt++;
      while (n % i == 0) {
        n /= i;
      }
    }
  }
  if (n != 1)
    cnt++;
  cout << cnt << '\n';
}
Problem p02900 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int GCD(int a, int b) {
  if (a % b == 0)
    return b;
  return GCD(b, a % b);
}

// 素因数分解
vector<pair<long long, long long>> prime_factorize(long long N) {
  vector<pair<long long, long long>> res;
  for (long long a = 2; a * a <= N; ++a) {
    if (N % a != 0)
      continue;
    long long ex = 0; // 指数

    // 割れる限り割り続ける
    while (N % a == 0) {
      ++ex;
      N /= a;
    }

    // その結果を push
    res.push_back({a, ex});
  }

  // 最後に残った数について
  if (N != 1)
    res.push_back({N, 1});
  return res;
}

int main() {
  ll A, B;
  cin >> A >> B;
  ll g = GCD(A, B);
  auto pf = prime_factorize(g);
  ll ans = 1;
  for (auto p : pf)
    ans++;
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

// 素因数分解
vector<pair<long long, long long>> prime_factorize(long long N) {
  vector<pair<long long, long long>> res;
  for (long long a = 2; a * a <= N; ++a) {
    if (N % a != 0)
      continue;
    long long ex = 0; // 指数

    // 割れる限り割り続ける
    while (N % a == 0) {
      ++ex;
      N /= a;
    }

    // その結果を push
    res.push_back({a, ex});
  }

  // 最後に残った数について
  if (N != 1)
    res.push_back({N, 1});
  return res;
}

int main() {
  ll A, B;
  cin >> A >> B;
  ll g = GCD(A, B);
  auto pf = prime_factorize(g);
  ll ans = 1;
  for (auto p : pf)
    ans++;
  cout << ans << endl;
}
Problem p02900 (C++)

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

using namespace std;

long long gcd(long long x, long long y) {
  if (y)
    return gcd(y, x % y);
  else
    return x;
}

int main() {
  long long a, b;
  cin >> a >> b;
  long long g = gcd(a, b);
  long long count = 1;
  int i;
  for (i = 2; i * i <= g; i++) {
    if (g % i)
      continue;
    count++;
    while (g % i == 0)
      g /= i;
  }
  if (g >= i)
    count++;
  cout << count;
}

Fixed submission:
#include <iostream>

using namespace std;

long long gcd(long long x, long long y) {
  if (y)
    return gcd(y, x % y);
  else
    return x;
}

int main() {
  long long a, b;
  cin >> a >> b;
  long long g = gcd(a, b);
  long long i, count = 1;
  for (i = 2; i * i <= g; i++) {
    if (g % i)
      continue;
    count++;
    while (g % i == 0)
      g /= i;
  }
  if (g >= i)
    count++;
  cout << count;
}
Problem p02900 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define IO_OP                                                                  \
  std::ios::sync_with_stdio(0);                                                \
  std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

int32_t main() {
  IO_OP;

  ll a, b, g, ans = 1;
  cin >> a >> b;
  g = __gcd(a, b);
  for (int i = 2; i * i <= g; i++) {
    if (g % i)
      continue;
    ans++;
    while (g % i == 0)
      g /= i;
  }
  if (g != 1)
    ans++;
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define IO_OP                                                                  \
  std::ios::sync_with_stdio(0);                                                \
  std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

int32_t main() {
  IO_OP;

  ll a, b, g, ans = 1;
  cin >> a >> b;
  g = __gcd(a, b);
  for (ll i = 2; i * i <= g; i++) {
    if (g % i)
      continue;
    ans++;
    while (g % i == 0)
      g /= i;
  }
  if (g != 1)
    ans++;
  cout << ans << endl;
}
Problem p02900 (C++)

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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

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

#include <set>

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  ll g = gcd(n, m);
  set<ll> fact;
  ll t = g;
  for (int i = 2; i * i <= g; i++) {
    while (t % i == 0) {
      t /= i;
      fact.insert(i);
    }
  }
  if (t != 1) {
    fact.insert(t);
  }
  cout << fact.size() + 1 << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

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

#include <set>

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  ll g = gcd(n, m);
  set<ll> fact;
  ll t = g;
  for (ll i = 2; i * i <= g; i++) {
    while (t % i == 0) {
      t /= i;
      fact.insert(i);
    }
  }
  if (t != 1) {
    fact.insert(t);
  }
  cout << fact.size() + 1 << endl;
  return 0;
}
Problem p02900 (C++)

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

vector<long long> divisor(long long n) {
  vector<long long> ret;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end()); // 昇順に並べる
  return ret;
}
int main() {
  long long ans = 1;
  long long A, B;
  cin >> A >> B;
  long long MAX = max(A, B);
  vector<long long> V(MAX + 1, 1), I;
  V[1] = 0;
  vector<long long> a = divisor(A), b = divisor(B);
  set_intersection(a.begin(), a.end(), b.begin(), b.end(), back_inserter(I));
  sort(I.begin(), I.end());
  for (long long x : I) {
    if (V[x] == 1) {
      ans++;
      long long y = x;
      while (y <= MAX) {
        V[y] = 0;
        y += x;
      }
    }
  }

  cout << ans << endl;
}

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

vector<long long> divisor(long long n) {
  vector<long long> ret;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end()); // 昇順に並べる
  return ret;
}
int main() {
  long long ans = 1;
  long long A, B;
  cin >> A >> B;
  long long MIN = min(A, B), MAX = max(A, B);
  vector<long long> a = divisor(MIN);
  queue<long long> q;
  for (long long x : a) {
    if (MAX % x == 0)
      q.push(x);
  }
  q.pop();
  while (!q.empty()) {
    long long x = q.front();
    ans++;
    long long s = q.size();
    for (int i = 0; i < s; i++) {
      long long y = q.front();
      q.pop();
      if (y % x != 0)
        q.push(y);
    }
  }

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

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

long long calc_gcd(long long a, long long b) {
  long long x = max(a, b), y = min(a, b);
  if (y == 0) {
    return x;
  } else {
    return calc_gcd(b, a % b);
  }
}

int main() {
  long long A, B;
  cin >> A >> B;

  long long gcd = calc_gcd(A, B);
  // cout << "gcd: " << gcd << endl;

  int ans = 1; // for 1
  for (int i = 2; i * i <= gcd; i++) {
    if (gcd % i == 0) {
      ans++;
    }
    while (gcd % i == 0) {
      gcd /= i;
    }
  }
  if (gcd != 1) {
    ans++;
  }

  cout << ans << endl;
}


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

long long calc_gcd(long long a, long long b) {
  long long x = max(a, b), y = min(a, b);
  if (y == 0) {
    return x;
  } else {
    return calc_gcd(b, a % b);
  }
}

int main() {
  long long A, B;
  cin >> A >> B;

  long long gcd = calc_gcd(A, B);
  // cout << "gcd: " << gcd << endl;

  int ans = 1; // for 1
  for (long long i = 2; i * i <= gcd; i++) {
    if (gcd % i == 0) {
      ans++;
    }
    while (gcd % i == 0) {
      gcd /= i;
    }
  }
  if (gcd != 1) {
    ans++;
  }

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

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

vector<pair<ll, ll>> prime_factorize(ll n) {
  vector<pair<ll, ll>> res;
  for (int i = 2; i * i < n; ++i) {
    ll num = 0;
    if (n % i != 0)
      continue;
    while (n % i == 0) {
      ++num;
      n /= i;
    }
    res.push_back(make_pair(i, num));
  }
  if (n != 1)
    res.push_back(make_pair(n, 1));
  return res;
}

ll gcd(ll x, ll y) {
  if (x % y == 0)
    return y;
  else
    return gcd(y, x % y);
}

int main() {
  ll a, b;
  cin >> a >> b;
  ll x = gcd(a, b);
  auto pf = prime_factorize(x);
  cout << pf.size() + 1 << endl;
}


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

vector<pair<ll, ll>> prime_factorize(ll n) {
  vector<pair<ll, ll>> res;
  for (ll i = 2; i * i < n; ++i) {
    ll num = 0;
    if (n % i != 0)
      continue;
    while (n % i == 0) {
      ++num;
      n /= i;
    }
    res.push_back(make_pair(i, num));
  }
  if (n != 1)
    res.push_back(make_pair(n, 1));
  return res;
}

ll gcd(ll x, ll y) {
  if (x % y == 0)
    return y;
  else
    return gcd(y, x % y);
}

int main() {
  ll a, b;
  cin >> a >> b;
  ll x = gcd(a, b);
  auto pf = prime_factorize(x);
  cout << pf.size() + 1 << endl;
}
Problem p02900 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
const double PI = 3.14159265358979323846;

ll gcd(int x, int y) {
  if (x % y == 0)
    return y;
  else {
    return gcd(y, x % y);
  }
}

vector<pair<ll, ll>> prime_factorize(ll n) {
  vector<pair<ll, ll>> res;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i != 0)
      continue;
    ll num = 0;
    while (n % i == 0) {
      ++num;
      n /= i;
    }
    res.push_back(make_pair(i, num));
  }
  if (n != 1)
    res.push_back(make_pair(n, 1));
  return res;
}

int main() {
  ll a, b;
  cin >> a >> b;
  ll x = gcd(a, b);
  auto pf = prime_factorize(x);
  cout << pf.size() + 1 << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
const double PI = 3.14159265358979323846;

ll gcd(ll x, ll y) {
  if (x % y == 0)
    return y;
  else {
    return gcd(y, x % y);
  }
}

vector<pair<ll, ll>> prime_factorize(ll n) {
  vector<pair<ll, ll>> res;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i != 0)
      continue;
    ll num = 0;
    while (n % i == 0) {
      ++num;
      n /= i;
    }
    res.push_back(make_pair(i, num));
  }
  if (n != 1)
    res.push_back(make_pair(n, 1));
  return res;
}

int main() {
  ll a, b;
  cin >> a >> b;
  ll x = gcd(a, b);
  auto pf = prime_factorize(x);
  cout << pf.size() + 1 << endl;
}
Problem p02900 (C++)

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

#define int long long

using namespace std;

set<int> pfact(int a) {
  set<int> ret;
  // cout<<1<<endl;
  for (int i = 2; i * i <= a; i++) {
    // cout<<i<<endl;
    if (a % i == 0)
      ret.insert(i);
    while (a % i == 0)
      a /= i;
  }
  // cout<<2<<endl;
  if (a != 1) {
    ret.insert(a);
  }
  return ret;
}

void solve() {
  int a, b;
  int cnt = 1;
  cin >> a >> b;
  // cout<<"ho"<<endl;
  auto A = pfact(a);
  auto B = pfact(b);
  // cout<<"hei"<<endl;
  for (auto it = A.begin(); it != A.end(); it++) {
    if (B.find(*it) != B.end())
      cnt++;
    // cout<<*it<<endl;
  }
  cout << cnt << endl;
}

signed main() {
  while (1)
    solve();
}

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

#define int long long

using namespace std;

set<int> pfact(int a) {
  set<int> ret;
  // cout<<1<<endl;
  for (int i = 2; i * i <= a; i++) {
    // cout<<i<<endl;
    if (a % i == 0)
      ret.insert(i);
    while (a % i == 0)
      a /= i;
  }
  // cout<<2<<endl;
  if (a != 1) {
    ret.insert(a);
  }
  return ret;
}

void solve() {
  int a, b;
  int cnt = 1;
  cin >> a >> b;
  // cout<<"ho"<<endl;
  auto A = pfact(a);
  auto B = pfact(b);
  // cout<<"hei"<<endl;
  for (auto it = A.begin(); it != A.end(); it++) {
    if (B.find(*it) != B.end())
      cnt++;
    // cout<<*it<<endl;
  }
  cout << cnt << endl;
}

signed main() {
  // while(1)
  solve();
}
Problem p02900 (C++)

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(), (v).end()

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vii = vector<vector<int>>;

const ll LINF = 1LL << 60;
const int INF = 1 << 29;
const ll MOD = 1e9 + 7;

vector<ll> prime_fac(ll n) {
  vector<ll> res;
  for (int i = 2; i * i <= n; i++) {
    bool ok = false;
    while (n % i == 0) {
      n /= i;
      ok = true;
    }
    if (ok)
      res.push_back(i);
  }
  if (n != 1)
    res.push_back(n);
  return res;
}

int main() {
  ll A, B;
  cin >> A >> B;
  vector<bool> check(1001001, 0);
  vector<ll> fac;
  fac = prime_fac(A);
  ll res = 0;
  for (auto &x : fac) {
    if (B % x == 0)
      res++;
  }
  res++;
  cout << res << endl;
  return 0;
}

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(), (v).end()

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vii = vector<vector<int>>;

const ll LINF = 1LL << 60;
const int INF = 1 << 29;
const ll MOD = 1e9 + 7;

vector<ll> prime_fac(ll n) {
  vector<ll> res;
  for (ll i = 2; i * i <= n; i++) {
    bool ok = false;
    while (n % i == 0) {
      n /= i;
      ok = true;
    }
    if (ok)
      res.push_back(i);
  }
  if (n != 1)
    res.push_back(n);
  return res;
}

int main() {
  ll A, B;
  cin >> A >> B;
  vector<bool> check(1001001, 0);
  vector<ll> fac;
  fac = prime_fac(A);
  ll res = 0;
  for (auto &x : fac) {
    if (B % x == 0)
      res++;
  }
  res++;
  cout << res << endl;
  return 0;
}
Problem p02900 (C++)

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

vector<ll> factor(ll a) {
  vector<ll> v;
  for (int i = 2; i * i <= a; i++) {
    if (a % i != 0)
      continue;
    while (a % i == 0)
      a /= i;
    v.push_back(i);
  }
  if (a > 1)
    v.push_back(a);
  return v;
}

int main() {
  ll a, b;
  cin >> a >> b;
  map<ll, int> m;
  for (auto e : factor(a))
    m[e]++;
  for (auto e : factor(b))
    m[e]++;
  int ans = 0;
  for (auto &e : m)
    if (e.second == 2)
      ans++;
  cout << ans + 1 << endl;
  return 0;
}

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

vector<ll> factor(ll a) {
  vector<ll> v;
  for (ll i = 2; i * i <= a; i++) {
    if (a % i != 0)
      continue;
    while (a % i == 0)
      a /= i;
    v.push_back(i);
  }
  if (a > 1)
    v.push_back(a);
  return v;
}

int main() {
  ll a, b;
  cin >> a >> b;
  map<ll, int> m;
  for (auto e : factor(a))
    m[e]++;
  for (auto e : factor(b))
    m[e]++;
  int ans = 0;
  for (auto &e : m)
    if (e.second == 2)
      ans++;
  cout << ans + 1 << endl;
  return 0;
}
Problem p02900 (C++)

Buggy submission (status: Time Limit Exceeded):
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author TM
 */

#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define SIZE 100005
#define MOD 1000000007
#define INF 100000000

using namespace std;

class DDisjointSetOfCommonDivisors {
public:
  void PrimeFactorize(int64_t N, set<int64_t> &vec) {
    for (int i = 2; i * i <= N; i++) {
      while (N % i == 0) {
        vec.insert(i);
        N /= i;
      }
    }
    vec.insert(N);
    vec.insert(1);
  }

  void solve(std::istream &cin, std::ostream &cout) {
    long a, b;
    cin >> a >> b;
    set<int64_t> a_vec;
    set<int64_t> b_vec;
    PrimeFactorize(a, a_vec);
    PrimeFactorize(b, b_vec);
    int64_t cnt = 0;
    for (const auto &a_item : a_vec) {
      for (const auto &b_item : b_vec) {
        if (a_item == b_item) {
          cnt++;
        }
      }
    }
    cout << cnt << endl;
  }
};

int main() {
  DDisjointSetOfCommonDivisors solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}


Fixed submission:
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author TM
 */

#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define SIZE 100005
#define MOD 1000000007
#define INF 100000000

using namespace std;

class DDisjointSetOfCommonDivisors {
public:
  void PrimeFactorize(int64_t N, set<int64_t> &vec) {
    for (int64_t i = 2; i * i <= N; i++) {
      while (N % i == 0) {
        vec.insert(i);
        N /= i;
      }
    }
    vec.insert(N);
    vec.insert(1);
  }

  void solve(std::istream &cin, std::ostream &cout) {
    long a, b;
    cin >> a >> b;
    set<int64_t> a_vec;
    set<int64_t> b_vec;
    PrimeFactorize(a, a_vec);
    PrimeFactorize(b, b_vec);
    int64_t cnt = 0;
    for (const auto &a_item : a_vec) {
      for (const auto &b_item : b_vec) {
        if (a_item == b_item) {
          cnt++;
        }
      }
    }
    cout << cnt << endl;
  }
};

int main() {
  DDisjointSetOfCommonDivisors solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}
Problem p02900 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }
int main() {
  long long a, b, ans = 0, k, i = 2;
  cin >> a >> b;

  k = (a > b ? gcd(a, b) : gcd(b, a));
  while (k > 1) {
    if (k % i == 0) {
      ans++;
      while (k % i == 0)
        k /= i;
    }
    i++;
  }

  cout << ans + 1 << endl;
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }
int main() {
  long long a, b, ans = 0, k, i = 2;
  cin >> a >> b;

  k = (a > b ? gcd(a, b) : gcd(b, a));
  while (k > 1) {
    if (i * i > k) {
      ans++;
      break;
    }
    if (k % i == 0) {
      ans++;
      while (k % i == 0)
        k /= i;
    }
    i++;
  }

  cout << ans + 1 << endl;
  return 0;
}
Problem p02900 (C++)

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  long long a, b;
  cin >> a >> b;
  long long g = __gcd(a, b);
  map<int, int> mp;
  for (int i = 2; i * i <= g; i++) {
    while (g % i == 0) {
      mp[i]++;
      g /= i;
    }
  }
  if (g > 1)
    mp[g]++;
  cout << mp.size() + 1 << endl;
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  long long a, b;
  cin >> a >> b;
  long long g = __gcd(a, b);
  map<int, int> mp;
  for (int i = 2; (long long)i * i <= g; i++) {
    while (g % i == 0) {
      mp[i]++;
      g /= i;
    }
  }
  if (g > 1)
    mp[g]++;
  cout << mp.size() + 1 << endl;
}
Problem p02900 (C++)

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

// refering to exp.
int main() {
  llong a, b;
  cin >> a >> b;

  llong n = __gcd(a, b);
  llong cnt = 1;
  for (int i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      cnt++;
      while (n % i == 0)
        n /= i;
    }
  }
  if (n != 1)
    cnt++;

  cout << cnt << endl;
}


Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long llong;

// refering to exp.
int main() {
  llong a, b;
  cin >> a >> b;

  llong n = __gcd(a, b);
  llong cnt = 1;
  for (llong i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      cnt++;
      while (n % i == 0)
        n /= i;
    }
  }
  if (n != 1)
    cnt++;

  cout << cnt << endl;
}
Problem p02900 (C++)

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

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

signed main() {
  int A, B, i;
  scanf("%lld%lld", &A, &B);
  int g = gcd(A, B);
  int ans = 0;
  for (i = 1; i * i <= g; i++) {
    if (g % i == 0) {
      while (g % i == 0) {
        g /= i;
      }
      ans++;
    }
  }
  if (g > 1) {
    ans++;
  }
  printf("%lld\n", ans);
  return 0;
}

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

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

signed main() {
  int A, B, i;
  scanf("%lld%lld", &A, &B);
  int g = gcd(A, B);
  int ans = 1;
  for (i = 2; i * i <= g; i++) {
    if (g % i == 0) {
      while (g % i == 0) {
        g /= i;
      }
      ans++;
    }
  }
  if (g > 1) {
    ans++;
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p02900 (C++)

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

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REAP(i, a, n) for (int i = (a); i < (n); i++)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(), v.end()
typedef long long ll;

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

int main() {
  ios::sync_with_stdio(false);

  ll a, b;
  cin >> a >> b;
  ll c = gcd(a, b);
  ll cou = 1;
  for (int i = 2; i * i <= c; i++) {
    if (c % i == 0) {
      cou++;
      while (c % i == 0) {
        c /= i;
      }
    }
  }
  if (c != 1)
    cou++;

  cout << cou << endl;
}


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

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REAP(i, a, n) for (int i = (a); i < (n); i++)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(), v.end()
typedef long long ll;

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

int main() {
  ios::sync_with_stdio(false);

  ll a, b;
  cin >> a >> b;
  ll c = gcd(a, b);
  ll cou = 1;
  for (ll i = 2; i * i <= c; i++) {
    if (c % i == 0) {
      cou++;
      while (c % i == 0) {
        c /= i;
      }
    }
  }
  if (c != 1)
    cou++;

  cout << cou << endl;
}
Problem p02900 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define mp make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i, a, n) for (int i = a; i < n; i++)
#define foreach(i, c)                                                          \
  for (__typeof(c.begin()) i = (c.begin()); i != (c).end(); i++)
#define pii pair<int, int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(), s.end()
#define zero(x) memset(x, 0, sizeof(x))
#define vii vector<pair<int, int>>
#define mpis map<int, string>
#define mpii map<int, int>
#define mpsi map<string, int>
#define re return
using namespace std;
long long a, b;
int main() {
  cin >> a >> b;
  long long gcd = __gcd(a, b);
  if (gcd == 1) {
    cout << 1;
    return 0;
  }
  int ans = 1;
  for (int i = 2; (long long)(i * i) <= gcd; i++) {
    if (gcd % i == 0)
      ans++;
    while (gcd % i == 0)
      gcd /= i;
  }
  if (gcd > 1)
    cout << ans + 1;
  else
    cout << ans;
  re 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define mp make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i, a, n) for (int i = a; i < n; i++)
#define foreach(i, c)                                                          \
  for (__typeof(c.begin()) i = (c.begin()); i != (c).end(); i++)
#define pii pair<int, int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(), s.end()
#define zero(x) memset(x, 0, sizeof(x))
#define vii vector<pair<int, int>>
#define mpis map<int, string>
#define mpii map<int, int>
#define mpsi map<string, int>
#define re return
using namespace std;
long long a, b;
int main() {
  cin >> a >> b;
  long long gcd = __gcd(a, b);
  if (gcd == 1) {
    cout << 1;
    return 0;
  }
  long long ans = 1;
  for (long long i = 2; (long long)(i * i) <= gcd; i++) {
    if (gcd % i == 0)
      ans++;
    while (gcd % i == 0)
      gcd /= i;
  }
  if (gcd > 1)
    cout << ans + 1;
  else
    cout << ans;
  re 0;
}
Problem p02900 (C++)

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

#define int long long

int tbl[1000010] = {};
vector<int> so;

signed main() {

  int a, b;
  cin >> a >> b;

  for (int i = 2; i * i <= max(a, b); i++) {
    if (tbl[i] == 0) {
      so.push_back(i);
      for (int j = i * 2; j <= max(a, b); j += i) {
        tbl[i] = 1;
      }
    }
  }

  int idx = 0;

  set<int> st;

  int tmp = a;
  while (1) {

    if (tmp == 1)
      break;

    if (idx == so.size()) {
      st.insert(tmp);
      break;
    }

    if (tmp % so[idx] == 0) {
      tmp /= so[idx];
      st.insert(so[idx]);
    } else {
      idx++;
    }
  }

  tmp = b;

  int ans = 0;
  idx = 0;
  while (1) {
    if (tmp == 1)
      break;

    if (idx == so.size()) {
      if (st.find(tmp) != st.end()) {
        st.erase(tmp);
        ans++;
      }
      break;
    }

    if (tmp % so[idx] == 0) {
      if (st.find(so[idx]) != st.end()) {
        st.erase(so[idx]);
        ans++;
      }
      tmp /= so[idx];
    } else {
      idx++;
    }
  }

  cout << ans + 1 << endl;

  return 0;
}


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

#define int long long

int tbl[1000010] = {};
vector<int> so;

signed main() {

  int a, b;
  cin >> a >> b;

  for (int i = 2; i * i <= max(a, b); i++) {
    if (tbl[i] == 0) {
      so.push_back(i);
      for (int j = i * 2; j * j <= max(a, b); j += i) {
        tbl[i] = 1;
      }
    }
  }

  int idx = 0;

  set<int> st;

  int tmp = a;
  while (1) {

    if (tmp == 1)
      break;

    if (idx == so.size()) {
      st.insert(tmp);
      break;
    }

    if (tmp % so[idx] == 0) {
      tmp /= so[idx];
      st.insert(so[idx]);
    } else {
      idx++;
    }
  }

  tmp = b;

  int ans = 0;
  idx = 0;
  while (1) {
    if (tmp == 1)
      break;

    if (idx == so.size()) {
      if (st.find(tmp) != st.end()) {
        st.erase(tmp);
        ans++;
      }
      break;
    }

    if (tmp % so[idx] == 0) {
      if (st.find(so[idx]) != st.end()) {
        st.erase(so[idx]);
        ans++;
      }
      tmp /= so[idx];
    } else {
      idx++;
    }
  }

  cout << ans + 1 << endl;

  return 0;
}
Problem p02900 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long A, B;
  cin >> A >> B;
  long long AA, BB;
  AA = A, BB = B;
  long long k = 1;
  long long j = 0;
  while (k > 0) {
    j = A / B;
    k = A % B;
    A = B;
    B = k;
  }

  int count = 1;
  long long E = A;
  int x = max(sqrt(AA), sqrt(BB));
  // cout<<x;
  for (int i = 2; i < A - 1; i++) {
    if (E % i == 0) {
      while (E % i == 0) {
        E = E / i;
      }
      count++;
    }
    if (E < i) {
      break;
    }
  }
  if (E > 1) {
    count++;
  }
  cout << count << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long A, B;
  cin >> A >> B;
  long long AA, BB;
  AA = A, BB = B;
  long long k = 1;
  long long j = 0;
  while (k > 0) {
    j = A / B;
    k = A % B;
    A = B;
    B = k;
  }

  int count = 1;
  long long E = A;
  int x = max(sqrt(AA), sqrt(BB));
  // cout<<x;
  for (int i = 2; i < x; i++) {
    if (E % i == 0) {
      while (E % i == 0) {
        E = E / i;
      }
      count++;
    }
    if (E < i) {
      break;
    }
  }
  if (E > 1) {
    count++;
  }
  cout << count << endl;
}
Problem p02900 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, b, a) for (int i = (b)-1; i >= 0; --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define SORT(v) sort(v.begin(), v.end())
#define REV(v) reverse(v.begin(), v.end())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll A, B;
  cin >> A >> B;
  ll g = gcd(A, B);
  ll res = 1;
  for (int i = 2; i * i <= g; ++i) {
    if (g % i == 0)
      ++res;
    while (g % i == 0)
      g /= i;
  }
  if (g > 1)
    ++res;
  cout << res << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, b, a) for (int i = (b)-1; i >= 0; --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define SORT(v) sort(v.begin(), v.end())
#define REV(v) reverse(v.begin(), v.end())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll A, B;
  cin >> A >> B;
  ll g = gcd(A, B);
  ll res = 1;
  for (ll i = 2; i * i <= g; ++i) {
    if (g % i == 0)
      ++res;
    while (g % i == 0)
      g /= i;
  }
  if (g > 1)
    ++res;
  cout << res << endl;

  return 0;
}
Problem p02900 (C++)

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

// Aの約数とBの約数のから互いに素であるものを選んだ時の最大個数
// gcd(A,B)の因数のうち互いに素であるものの個数
// gcd(A,B)の素因数の個数

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

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] = 1;
  return res;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll a, b;
  cin >> a >> b;
  ll d;
  d = gcd(a, b);
  map<ll, ll> pf;
  pf = prime_factor(d);
  ll ans = 1;
  for (ll i = 0; i <= d; i++) {
    ll t = 0;
    if (pf.find(i) == pf.end())
      continue;
    ans++;
  }
  cout << ans << endl;
  return 0;
}


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

// Aの約数とBの約数のから互いに素であるものを選んだ時の最大個数
// gcd(A,B)の因数のうち互いに素であるものの個数
// gcd(A,B)の素因数の個数

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

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] = 1;
  return res;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll a, b;
  cin >> a >> b;
  ll d;
  d = gcd(a, b);
  map<ll, ll> pf;
  pf = prime_factor(d);
  ll ans = 1;
  ans += pf.size();

  cout << ans << endl;
  return 0;
}
Problem p02900 (C++)

Buggy submission (status: Time Limit Exceeded):
/**
 *    author:  souzai32
 *    created: 13.08.2020 01:17:53
 **/

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

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

long lcm(long a, long b) { return a * b / gcd(a, b); }

int main() {

  long a, b;
  cin >> a >> b;
  long num = gcd(a, b);
  int count = 1;

  for (int i = 2; i * i <= num; i++) {
    if (num % i != 0)
      continue;
    while (num % i == 0) {
      num /= i;
    }
    count++;
  }
  if (num != 1)
    count++;

  cout << count << endl;

  return 0;
}

Fixed submission:
/**
 *    author:  souzai32
 *    created: 13.08.2020 01:17:53
 **/

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

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

long lcm(long a, long b) { return a * b / gcd(a, b); }

int main() {

  long a, b;
  cin >> a >> b;
  long num = gcd(a, b);
  int count = 1;

  for (long i = 2; i * i <= num; i++) {
    if (num % i != 0)
      continue;
    while (num % i == 0) {
      num /= i;
    }
    count++;
  }
  if (num != 1)
    count++;

  cout << count << endl;

  return 0;
}
Problem p02900 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

template <typename T> T gcd(T a, T b) {
  if (a == 0)
    return b;
  return gcd(b % a, a);
}

template <typename T> T lcm(T a, T b) { return (a * b) / gcd(b % a, a); }

ll PrimeFactorization(ll n) {
  ll ans = 0;
  for (int i = 2; i * i <= n && n != 1; ++i) {
    if (n % i == 0) {
      ans++;
      while (n % i == 0) {
        n /= i;
      }
    }
  }
  if (n != 1)
    ans++;
  ans++; // 1の分を足す
  return ans;
}

void Print(ll n, unordered_map<ll, ll> &m) {
  cout << n << " = ";
  bool first = true;
  for (const auto &e : m) {
    rep(i, e.second) {
      if (!first)
        cout << " * ";
      cout << e.first;
      first = false;
    }
  }
  cout << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);

  ll a, b;
  cin >> a >> b;
  cout << PrimeFactorization(gcd(a, b)) << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

template <typename T> T gcd(T a, T b) {
  if (a == 0)
    return b;
  return gcd(b % a, a);
}

template <typename T> T lcm(T a, T b) { return (a * b) / gcd(b % a, a); }

ll PrimeFactorization(ll n) {
  ll ans = 0;
  if (n % 2 == 0)
    ans++;
  while (n % 2 == 0)
    n = n / 2;

  for (int i = 3; i <= sqrt(n); i += 2) {
    if (n % i == 0) {
      ans++;
      while (n % i == 0) {
        n /= i;
      }
    }
  }
  if (n != 1)
    ans++;
  ans++; // 1の分を足す
  return ans;
}

void Print(ll n, unordered_map<ll, ll> &m) {
  cout << n << " = ";
  bool first = true;
  for (const auto &e : m) {
    rep(i, e.second) {
      if (!first)
        cout << " * ";
      cout << e.first;
      first = false;
    }
  }
  cout << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);

  ll a, b;
  cin >> a >> b;
  cout << PrimeFactorization(gcd(a, b)) << endl;
  return 0;
}
Problem p02900 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _LIBCPP_DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
typedef vector<int> vi;
typedef long long ll;

ll GCD(ll a, ll b) {
  if (b > a)
    return GCD(b, a);
  if (a % b == 0)
    return b;
  else
    return GCD(b, a % b);
}

int main() {
  ll A, B;
  cin >> A >> B;
  ll gcd = GCD(A, B), ans = 1;
  for (int i = 2; i * i <= gcd; i++) {
    if (gcd % i == 0) {
      ans++;
      while (gcd % i == 0) {
        gcd /= i;
      }
    }
  }
  if (gcd != 1)
    ans++;
  cout << ans << endl;
}


Fixed submission:
#define _LIBCPP_DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
typedef vector<int> vi;
typedef long long ll;

ll GCD(ll a, ll b) {
  if (b > a)
    return GCD(b, a);
  if (a % b == 0)
    return b;
  else
    return GCD(b, a % b);
}

int main() {
  ll A, B;
  cin >> A >> B;
  ll gcd = GCD(A, B), ans = 1;
  for (ll i = 2; i * i <= gcd; i++) {
    if (gcd % i == 0) {
      ans++;
      while (gcd % i == 0) {
        gcd /= i;
      }
    }
  }
  if (gcd != 1)
    ans++;
  cout << ans << endl;
}
Problem p02900 (C++)

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

ll a, b;

int main() {
  cin >> a >> b;
  ll x = __gcd(a, b);
  int tot = 0;
  for (int i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      tot++;
      while (x % i == 0)
        x /= i;
    }
  }
  if (x > 1)
    tot++;
  cout << tot + 1 << endl;
  return 0;
}

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

ll a, b;

int main() {
  cin >> a >> b;
  ll x = __gcd(a, b);
  int tot = 0;
  for (ll i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      tot++;
      while (x % i == 0)
        x /= i;
    }
  }
  if (x > 1)
    tot++;
  cout << tot + 1 << endl;
  return 0;
}