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

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

long long gcd(long long A, long long B) {
  if (B == 0) {
    return A;
  }
  return gcd(B, A % B);
}

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

int main() {
  long long A, B;
  cin >> A >> B;
  long long C = gcd(A, B);
  vector<pair<long long, long long>> D = prime_factorize(C);
  cout << D.size() + 1 << endl;
}

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

long long gcd(long long A, long long B) {
  if (B == 0) {
    return A;
  }
  return gcd(B, A % B);
}

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

int main() {
  long long A, B;
  cin >> A >> B;
  long long C = gcd(A, B);
  vector<pair<long long, long long>> D = prime_factorize(C);
  cout << D.size() + 1 << endl;
}
Problem p02900 (C++)

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

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() {

  long long a, b;
  cin >> a >> b;

  vector<pair<long long, long long>> a_prime;
  vector<pair<long long, long long>> b_prime;

  a_prime = prime_factorize(a);
  b_prime = prime_factorize(b);

  vector<long long> c;
  for (long long i = 0; i < a_prime.size(); i++) {
    c.push_back(a_prime[i].first);
  }
  for (long long i = 0; i < b_prime.size(); i++) {
    c.push_back(b_prime[i].first);
  }

  sort(c.begin(), c.end());

  long long ans = 1; // 1を考慮
  for (long long i = 0; i < c.size() - 1LL; i++) {
    if (c[i] == c[i + 1]) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

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() {

  long long a, b;
  cin >> a >> b;

  if (a == 1 || b == 1) {
    cout << 1 << endl;
    return 0;
  }

  vector<pair<long long, long long>> a_prime;
  vector<pair<long long, long long>> b_prime;

  a_prime = prime_factorize(a);
  b_prime = prime_factorize(b);

  vector<long long> c;
  for (long long i = 0; i < a_prime.size(); i++) {
    c.push_back(a_prime[i].first);
  }
  for (long long i = 0; i < b_prime.size(); i++) {
    c.push_back(b_prime[i].first);
  }

  sort(c.begin(), c.end());

  long long ans = 1; // 1を考慮
  for (long long i = 0; i < c.size() - 1LL; i++) {
    if (c[i] == c[i + 1]) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02900 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long INF = 1e15;

#include <math.h>
#define PI 3.14159265358979323846264338327950L

bool isPrime(long long x) {
  if (x == 1)
    return true;
  for (long long i = 2; i < x; i++) {
    if (x % i == 0)
      return false;
  }
  return true;
}

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

vector<long long> common_divisors(long long a, long long b) {
  long long n = gcd(a, b);
  vector<long long> ans;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      if (n / i == i) {
        ans.push_back(i);
      } else {
        ans.push_back(n / i);
        ans.push_back(i);
      }
    }
  }
  return ans;
}

int main() {
  long long a, b;
  cin >> a >> b;
  vector<long long> div = common_divisors(a, b);
  long long ans = 0;
  for (int i = 0; i < div.size(); i++)
    if (isPrime(div[i]))
      ans++;
  cout << ans;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long INF = 1e15;

#include <math.h>
#define PI 3.14159265358979323846264338327950L

bool isPrime(long long x) {
  if (x == 1)
    return true;
  for (long long i = 2; i * i <= x; i++) {
    if (x % i == 0)
      return false;
  }
  return true;
}

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

vector<long long> common_divisors(long long a, long long b) {
  long long n = gcd(a, b);
  vector<long long> ans;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      if (n / i == i) {
        ans.push_back(i);
      } else {
        ans.push_back(n / i);
        ans.push_back(i);
      }
    }
  }
  return ans;
}

int main() {
  long long a, b;
  cin >> a >> b;
  vector<long long> div = common_divisors(a, b);
  long long ans = 0;
  for (int i = 0; i < div.size(); i++)
    if (isPrime(div[i]))
      ans++;
  cout << ans;

  return 0;
}
Problem p02900 (C++)

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

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

int main() {
  long long a, b;
  cin >> a >> b;
  long long n = gcd(a, b);
  vector<pair<long long, long long>> fs;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      int cnt = 0;
      while (n % i == 0) {
        n /= i;
        cnt++;
      }
      fs.emplace_back(i, cnt);
    }
  }
  if (n > 1) {
    fs.emplace_back(n, 1);
  }
  cout << fs.size() + 1 << endl;
}


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

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

int main() {
  long long a, b;
  cin >> a >> b;
  long long n = gcd(a, b);
  vector<pair<long long, long long>> fs;
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      int cnt = 0;
      while (n % i == 0) {
        n /= i;
        cnt++;
      }
      fs.emplace_back(i, cnt);
    }
  }
  if (n > 1) {
    fs.emplace_back(n, 1);
  }
  cout << fs.size() + 1 << endl;
}
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++)

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

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

  long long n = gcd(A, B);

  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 <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

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

  long long n = gcd(A, B);

  cnt = 1;

  for (long long 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 <iostream>
#define ll long long
using namespace std;

ll gcd(ll a, ll b) {
  ll t = a % b;
  while (t > 0) {
    a = b;
    b = t;
    t = a % b;
  }
  return b;
}

int main() {
  ll A, B, ans = 1;
  cin >> A >> B;

  ll N = gcd(A, B);
  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 << endl;
}

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

ll gcd(ll a, ll b) {
  ll t = a % b;
  while (t > 0) {
    a = b;
    b = t;
    t = a % b;
  }
  return b;
}

int main() {
  ll A, B, ans = 1;
  cin >> A >> B;

  ll N = gcd(A, B);
  for (ll i = 2; i * i <= N; i++) {
    if (N % i == 0) {
      ans++;
      while (N % i == 0)
        N /= i;
    }
  }
  if (N > 1)
    ans++;
  cout << ans << endl;
}
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;
  else
    return gcd(b, a % b);
}

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

  cout << count << endl;
}

int main() {
  solve();
  return 0;
}


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;
  else
    return gcd(b, a % b);
}

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

  cout << count << endl;
}

int main() {
  solve();
  return 0;
}
Problem p02900 (C++)

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

using namespace std;

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

int main() {
  long long a, b;
  cin >> a >> b;
  long long g;
  if (a > b) {
    g = gcd(a, b);
  } else {
    g = gcd(b, a);
  }
  int count = 1;

  for (int i = 2; i * i <= g; i++) {
    if (g % i == 0) {
      count++;
      while (g % i == 0)
        g /= i;
    }
  }

  if (g != 1)
    count++;
  printf("%d\n", count);
  return 0;
}

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

using namespace std;

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

int main() {
  long long a, b;
  cin >> a >> b;
  long long g;
  if (a > b) {
    g = gcd(a, b);
  } else {
    g = gcd(b, a);
  }
  int count = 1;

  for (long long i = 2; i * i <= g; i++) {
    if (g % i == 0) {
      count++;
      while (g % i == 0)
        g /= i;
    }
  }

  if (g != 1)
    count++;
  printf("%d\n", count);
  return 0;
}
Problem p02900 (C++)

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

int64_t gcd(int64_t a, int64_t b) { return b != 0 ? gcd(b, a % b) : a; }

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

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

  return 0;
}


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

int64_t gcd(int64_t a, int64_t b) { return b != 0 ? gcd(b, a % b) : a; }

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

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

  return 0;
}
Problem p02900 (C++)

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

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep2(i, s, n) for (int i = (s); i < (int)n; i++)
int INF = 1e9 + 7;

ll gcd(ll m, ll n) {
  if (m % n == 0)
    return n;
  return gcd(n, m % n);
}

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

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep2(i, s, n) for (int i = (s); i < (int)n; i++)
int INF = 1e9 + 7;

ll gcd(ll m, ll n) {
  if (m % n == 0)
    return n;
  return gcd(n, m % n);
}

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

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

int main() {
  int ans = 1;
  long long int a, b, tmp;
  vector<long long int> v;

  cin >> a >> b;

  // aの素数の約数を全て求める
  tmp = a;
  for (int i = 2; i <= (int)sqrt(tmp); i++) {
    int flag = 0;
    while (tmp % i == 0) {
      tmp /= i;
      // cout << "[" << tmp << "]";
      flag = 1;
    }
    if (flag == 1) {
      // cout << "(" << i << ")";
      v.push_back(i);
    }
    if (tmp < i) {
      break;
    }
  }
  if (tmp != 1 && v[v.size() - 1] != tmp) {
    v.push_back(tmp);
  }

  for (int i = 0; i < v.size(); i++) {
    // cout << "(" << v[i] << ")";
    if (b % v[i] == 0) {
      ans++;
    }
  }
  cout << ans;

  return 0;
}

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

int main() {
  int ans = 1;
  long long int a, b, tmp;
  vector<long long int> v;

  cin >> a >> b;

  // aの素数の約数を全て求める
  tmp = a;
  for (int i = 2; i <= (int)sqrt(tmp); i++) {
    int flag = 0;
    while (tmp % i == 0) {
      tmp /= i;
      // cout << "[" << tmp << "]";
      flag = 1;
    }
    if (flag == 1) {
      // cout << "(" << i << ")";
      v.push_back(i);
    }
    if (tmp < i) {
      break;
    }
  }
  if (v.size() > 0) {
    if (tmp != 1 && v[v.size() - 1] != tmp) {
      v.push_back(tmp);
    }
  } else {
    if (tmp != 1)
      v.push_back(tmp);
  }

  for (int i = 0; i < v.size(); i++) {
    // cout << "(" << v[i] << ")";
    if (b % v[i] == 0) {
      ans++;
    }
  }
  cout << ans;

  return 0;
}
Problem p02900 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a, b, c, ans = 0, p = 1, q = 1;
map<ll, int> mp;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> a >> b;
  c = __gcd(a, b);
  for (int i = 2; i * i <= c; i++) {
    while (c % i == 0) {
      mp[i]++;
      c /= i;
    }
  }
  if (c > 1)
    mp[c]++;
  cout << mp.size() + 1;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a, b, c, ans = 0, p = 1, q = 1;
map<ll, int> mp;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> a >> b;
  c = __gcd(a, b);
  for (ll i = 2; i * i <= c; i++) {
    while (c % i == 0) {
      mp[i]++;
      c /= i;
    }
  }
  if (c > 1)
    mp[c]++;
  cout << mp.size() + 1;
  return 0;
}
Problem p02900 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
// ax + by = gcd(a, b) O(logN)
long long extended_euclidean(long long a, long long b, long long &x,
                             long long &y) {
  x = 1;
  y = 0;
  long long u = 0, v = 1;
  long long ri = a, rj = b, rk, k;

  // [x y]
  // [u v]
  while (1) {
    k = ri / rj;
    rk = ri % rj;
    ri = rj;
    rj = rk;

    // [newx newy] = [0  1] [x y]
    // [newu newv] = [1 -k] [u v]
    long long newx, newy, newu, newv;
    newx = u;
    newy = v;
    newu = x - k * u;
    newv = y - k * v;
    x = newx;
    y = newy;
    u = newu;
    v = newv;

    if (rk == 0)
      break;
  }

  return a * x + b * y; // gcd
}
void prime_factorization(long long n, map<long long, int> &m) // O(sqrt(n))
{
  for (int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      n /= i;
      m[i]++;
    }
  }
  if (n != 1)
    m[n]++;
}
int main(void) {
  long long a, b;
  cin >> a >> b;
  long long x, y;
  long long gcd = extended_euclidean(a, b, x, y);

  map<long long, int> m;
  prime_factorization(gcd, m);
  cout << m.size() + 1 << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
// ax + by = gcd(a, b) O(logN)
long long extended_euclidean(long long a, long long b, long long &x,
                             long long &y) {
  x = 1;
  y = 0;
  long long u = 0, v = 1;
  long long ri = a, rj = b, rk, k;

  // [x y]
  // [u v]
  while (1) {
    k = ri / rj;
    rk = ri % rj;
    ri = rj;
    rj = rk;

    // [newx newy] = [0  1] [x y]
    // [newu newv] = [1 -k] [u v]
    long long newx, newy, newu, newv;
    newx = u;
    newy = v;
    newu = x - k * u;
    newv = y - k * v;
    x = newx;
    y = newy;
    u = newu;
    v = newv;

    if (rk == 0)
      break;
  }

  return a * x + b * y; // gcd
}
void prime_factorization(long long n, map<long long, int> &m) // O(sqrt(n))
{
  for (long long i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      n /= i;
      m[i]++;
    }
  }
  if (n != 1)
    m[n]++;
}
int main(void) {
  long long a, b;
  cin >> a >> b;
  long long x, y;
  long long gcd = extended_euclidean(a, b, x, y);

  map<long long, int> m;
  prime_factorization(gcd, m);
  cout << m.size() + 1 << endl;

  return 0;
}
Problem p02900 (C++)

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

typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)

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

// gcd(A, B)の約数（＝A, Bの公約数）を求める関数
// 求めた公約数は、vector<pair<ll,
// int>>型配列に入れられる。(firstが公約数の値、secondが出現回数)
vector<pair<ll, int>> factorize(ll n) {
  vector<pair<ll, int>> p;
  // Nの約数を求める時は、約数の候補は、1~sqrt(N)までを見ればよいことから、このようにする
  // 今回は1はmain関数内のarray.size()+1の+1で補っている
  for (int i = 2; i * i < n; i++) {
    if (n % i != 0)
      continue;
    p.emplace_back(i, 0);
    // iで何回割れるかを求める
    while (n % i == 0) {
      n /= i;
      p.back().second++;
    }
  }
  if (n != 1)
    p.emplace_back(n, 1);
  return p;
}

int main() {
  ll A, B;
  cin >> A >> B;
  ll g = gcd(A, B);
  auto array = factorize(g);
  ll ans = array.size() + 1;
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)

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

// gcd(A, B)の約数（＝A, Bの公約数）を求める関数
// 求めた公約数は、vector<pair<ll,
// int>>型配列に入れられる。(firstが公約数の値、secondが出現回数)
vector<pair<ll, int>> factorize(ll n) {
  vector<pair<ll, int>> p;
  // Nの約数を求める時は、約数の候補は、1~sqrt(N)までを見ればよいことから、このようにする
  // 今回は1はmain関数内のarray.size()+1の+1で補っている
  for (ll i = 2; i * i < n; i++) {
    if (n % i != 0)
      continue;
    p.emplace_back(i, 0);
    // iで何回割れるかを求める
    while (n % i == 0) {
      n /= i;
      p.back().second++;
    }
  }
  if (n != 1)
    p.emplace_back(n, 1);
  return p;
}

int main() {
  ll A, B;
  cin >> A >> B;
  ll g = gcd(A, B);
  auto array = factorize(g);
  ll ans = array.size() + 1;
  cout << ans << endl;
  return 0;
}
Problem p02900 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <map>
using namespace std;
#define N 100005
#define ll long long
#define MOD 1000000007
ll x, y;
map<ll, bool> vis;
ll p[N];
int pn;
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int main() {
  scanf("%lld %lld", &x, &y);
  ll d = gcd(x, y);
  int ans = 1;
  if (d % 2 == 0)
    ans++;
  while (d % 2 == 0)
    d /= 2;
  for (int i = 3; i * i <= d; i += 2)
    if (d % i == 0) {
      ans++;
      while (d % i == 0)
        d /= i;
    }
  if (d != 1)
    ans++;
  printf("%d\n", ans);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <map>
using namespace std;
#define N 100005
#define ll long long
#define MOD 1000000007
ll x, y;
map<ll, bool> vis;
ll p[N];
int pn;
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int main() {
  scanf("%lld %lld", &x, &y);
  ll d = gcd(x, y);
  int ans = 1;
  if (d % 2 == 0)
    ans++;
  while (d % 2 == 0)
    d /= 2;
  for (int i = 3; i <= d / i; i += 2)
    if (d % i == 0) {
      ans++;
      while (d % i == 0)
        d /= i;
    }
  if (d != 1)
    ans++;
  printf("%d\n", ans);
  return 0;
}
Problem p02900 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>

int main() {
  long long A, B;
  std::priority_queue<int> aque, bque;
  std::vector<int> d;
  scanf("%lld %lld", &A, &B);
  int amin = (int)std::sqrt(A), bmin = std::sqrt(B);
  for (int i = 1; i <= amin; ++i) {
    if (A % i == 0) {
      aque.push(i);
      if (i != A / i)
        aque.push(A / i);
    }
  }
  for (int i = 1; i <= bmin; ++i) {
    if (B % i == 0) {
      bque.push(i);
      if (i != B / i)
        bque.push(B / i);
    }
  }
  while (!aque.empty() && !bque.empty()) {
    if (aque.top() == bque.top()) {
      d.push_back(aque.top());
      aque.pop();
      bque.pop();
    } else if (aque.top() > bque.top()) {
      aque.pop();
    } else {
      bque.pop();
    }
  }
  std::reverse(d.begin(), d.end());
  for (int i = 1; i < d.size(); ++i) {
    for (auto j = d.begin() + i + 1; j < d.end(); ++j) {
      if ((*j) % d[i] == 0) {
        d.erase(j);
        --j;
      }
    }
  }
  std::cout << d.size() << std::endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>

int main() {
  long long A, B;
  std::priority_queue<long long> aque, bque;
  std::vector<long long> d;
  scanf("%lld %lld", &A, &B);
  int amin = (int)std::sqrt(A), bmin = std::sqrt(B);
  for (int i = 1; i <= amin; ++i) {
    if (A % i == 0) {
      aque.push(i);
      if (i != A / i)
        aque.push(A / i);
    }
  }
  for (int i = 1; i <= bmin; ++i) {
    if (B % i == 0) {
      bque.push(i);
      if (i != B / i)
        bque.push(B / i);
    }
  }
  while (!aque.empty() && !bque.empty()) {
    if (aque.top() == bque.top()) {
      d.push_back(aque.top());
      aque.pop();
      bque.pop();
    } else if (aque.top() > bque.top()) {
      aque.pop();
    } else {
      bque.pop();
    }
  }
  std::reverse(d.begin(), d.end());
  for (int i = 1; i < d.size(); ++i) {
    for (auto j = d.begin() + i + 1; j < d.end(); ++j) {
      if ((*j) % d[i] == 0) {
        d.erase(j);
        --j;
      }
    }
  }
  std::cout << d.size() << std::endl;
  return 0;
}
Problem p02900 (C++)

Buggy submission (status: Time Limit Exceeded):
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(a) a.begin(), a.end()
#define lb lower_bound
#define ub upper_bound
#define owo                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);
#define MOD (ll)(1e9 + 7)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d)                                                              \
  for (long blockTime = 0;                                                     \
       (blockTime == 0 ? (blockTime = clock()) != 0 : false);                  \
       debug("%s time : %.4fs\n", d,                                           \
             (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> PII;
typedef pair<int, int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll A, ll B) {
  if (!B)
    return A;
  return gcd(B, A % B);
}
int main() {
  ll a, b;
  cin >> a >> b;
  a = gcd(a, b);
  ll ans = 0;
  for (int i = 2; i * i <= a; i++) {
    if (a % i == 0) {
      ans++;
      while (a % i == 0)
        a /= i;
    }
  }
  if (a > 1)
    ans++;
  ans++;
  cout << ans;
}


Fixed submission:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(a) a.begin(), a.end()
#define lb lower_bound
#define ub upper_bound
#define owo                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);
#define MOD (ll)(1e9 + 7)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d)                                                              \
  for (long blockTime = 0;                                                     \
       (blockTime == 0 ? (blockTime = clock()) != 0 : false);                  \
       debug("%s time : %.4fs\n", d,                                           \
             (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> PII;
typedef pair<int, int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll A, ll B) {
  if (!B)
    return A;
  return gcd(B, A % B);
}
int main() {
  ll a, b;
  cin >> a >> b;
  a = gcd(a, b);
  ll ans = 0;
  for (ll i = 2; i * i <= a; i++) {
    if (a % i == 0) {
      ans++;
      while (a % i == 0)
        a /= i;
    }
  }
  if (a > 1)
    ans++;
  ans++;
  cout << ans;
}
Problem p02900 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <cmath>
typedef long long ll;
using namespace std;
vector<ll> arr;
stack<int> st;
queue<int> qu;
queue<pair<int, int>> qu2;
priority_queue<int> pq;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.xise())
#define mod 1000000007
#define reps(i, s, n) for (int i = s; i < n; i++)

// cerrはコメントアウトしなくても通る

bool IsPrime(ll num) {
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false; // 偶数はあらかじめ除く

  for (ll i = 0; i < arr.size(); i++) {
    if (num % arr[i] == 0) {
      // 素数ではない
      return false;
    }
  }

  // 素数である
  return true;
}

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

int main() {
  ll a, b;
  cin >> a >> b;
  ll c = gcd(a, b);
  ll ans = 1;
  cerr << 1 << endl;
  for (int i = 2; i * i <= c; i++) {
    if (c % i == 0) {
      while (c % i == 0) {
        c /= i;
      }
      ans++;
      cerr << i << endl;
    }
  }
  if (c != 0 && c != 1) {
    ans++;
    cerr << c << endl;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#include <cmath>
typedef long long ll;
using namespace std;
vector<ll> arr;
stack<int> st;
queue<int> qu;
queue<pair<int, int>> qu2;
priority_queue<int> pq;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.xise())
#define mod 1000000007
#define reps(i, s, n) for (int i = s; i < n; i++)

// cerrはコメントアウトしなくても通る

bool IsPrime(ll num) {
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false; // 偶数はあらかじめ除く

  for (ll i = 0; i < arr.size(); i++) {
    if (num % arr[i] == 0) {
      // 素数ではない
      return false;
    }
  }

  // 素数である
  return true;
}

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

int main() {
  ll a, b;
  cin >> a >> b;
  ll c = gcd(a, b);
  ll ans = 1;
  cerr << 1 << endl;
  double d = sqrt(c);
  for (ll i = 2; i <= d; i++) {
    if (c % i == 0) {
      while (c % i == 0) {
        c /= i;
      }
      ans++;
      cerr << i << endl;
    }
  }
  if (c != 0 && c != 1) {
    ans++;
    cerr << c << endl;
  }
  cout << ans << endl;
  return 0;
}
Problem p02900 (C++)

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

int64_t gcd(int64_t a, int64_t b) {
  int64_t g = max(a, b), l = min(a, b), n = l;
  while (g % l != 0) {
    n = l;
    l = g % l;
    g = n;
  }
  return l;
}

int main() {
  int64_t a, b;
  cin >> a >> b;
  int64_t n = gcd(a, b), 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 << endl;
  return 0;
}

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

int64_t gcd(int64_t a, int64_t b) {
  int64_t g = max(a, b), l = min(a, b), n = l;
  while (g % l != 0) {
    n = l;
    l = g % l;
    g = n;
  }
  return l;
}

int main() {
  int64_t a, b;
  cin >> a >> b;
  int64_t n = gcd(a, b);
  int ans = 1;
  for (int64_t i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      ans++;
      while (n % i == 0)
        n /= i;
    }
  }
  if (n != 1)
    ans++;
  cout << ans << endl;
  return 0;
}
Problem p02900 (C++)

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

int main() {
  long long int a, b;
  cin >> a >> b;
  long long int g = __gcd(a, b), ans = 1;
  bool is = 1;
  for (long long int i = 2; i <= g; i++) {
    if (is) {
      bool chc = 0;
      for (long long int j = 2; j <= sqrt(g); j++)
        if (!(g % j))
          chc = 1;
      if (!chc) {
        cout << ans + 1 << '\n';
        return 0;
      }
    }
    if (!(g % i) && (is = 1, ans++))
      while (!(g % i))
        g /= i;
  }
  cout << ans << '\n';
}

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

int main() {
  long long int a, b;
  cin >> a >> b;
  long long int g = __gcd(a, b), ans = 1;
  bool is = 1;
  for (long long int i = 2; i <= g; i++) {
    if (is) {
      bool chc = 0;
      for (long long int j = 2; j <= sqrt(g); j++)
        if (!(g % j))
          chc = 1;
      if (!chc) {
        cout << ans + 1 << '\n';
        return 0;
      }
      is = 0;
    }
    if (!(g % i) && (is = 1, ans++))
      while (!(g % i))
        g /= i;
  }
  cout << ans << '\n';
}
Problem p02900 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define llu unsigned long long int
#define Endl endl
#define mod 998244353
#define mkp make_pair
#define pb push_back
#define cin(n) scanf("%d", &n)
#define cout(n) printf("%d ", n)
#define sf(n) scanf("%d", &n)
#define pf(n) printf("%d ", n)
#define bitget(n) __builtin_popcountll(n)
ll dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
ll dy[] = {0, -1, -1, -1, 0, 1, 1, 1};
ll dxx[] = {1, -1, 0, 0};
ll dyy[] = {0, 0, -1, 1};
ll modexpo(ll x, ll y) {
  if (y == 0)
    return 1;
  if (y % 2) {
    ll viky = modexpo(x, y / 2);
    return (((x * viky) % mod) * viky) % mod;
  } else {
    ll viky = modexpo(x, y / 2);
    return (viky * viky) % mod;
  }
}
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
bool isvalid(ll x, ll y, ll n, ll m) {
  return (x >= 0 && x < n && y >= 0 && y < m);
}

ll prime[1000011];

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  for (ll i = 0; i <= 1000000; i++) {

    if (prime[i] == 0) {

      for (ll j = i; j * i <= 1000000; j++) {

        prime[i * j] = 1;
      }
    }
  }

  ll a, b;

  cin >> a >> b;

  ll p = gcd(a, b);
  ll ans = 1;

  for (int i = 2; i <= 1000000; i++) {

    if (prime[i] == 0 && (p % i == 0)) {

      ans++;
      while ((p % i) == 0) {

        p = p / i;
      }
    }
  }

  if (p != 1) {

    ans++;
  }

  cout << ans;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define llu unsigned long long int
#define Endl endl
#define mod 998244353
#define mkp make_pair
#define pb push_back
#define cin(n) scanf("%d", &n)
#define cout(n) printf("%d ", n)
#define sf(n) scanf("%d", &n)
#define pf(n) printf("%d ", n)
#define bitget(n) __builtin_popcountll(n)
ll dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
ll dy[] = {0, -1, -1, -1, 0, 1, 1, 1};
ll dxx[] = {1, -1, 0, 0};
ll dyy[] = {0, 0, -1, 1};
ll modexpo(ll x, ll y) {
  if (y == 0)
    return 1;
  if (y % 2) {
    ll viky = modexpo(x, y / 2);
    return (((x * viky) % mod) * viky) % mod;
  } else {
    ll viky = modexpo(x, y / 2);
    return (viky * viky) % mod;
  }
}
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
bool isvalid(ll x, ll y, ll n, ll m) {
  return (x >= 0 && x < n && y >= 0 && y < m);
}

ll prime[1000011];

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  for (ll i = 2; i <= 1000000; i++) {

    if (prime[i] == 0) {

      for (ll j = i; j * i <= 1000000; j++) {

        prime[i * j] = 1;
      }
    }
  }

  ll a, b;

  cin >> a >> b;

  ll p = gcd(a, b);
  ll ans = 1;

  for (int i = 2; i <= 1000000; i++) {

    if (prime[i] == 0 && (p % i == 0)) {

      ans++;
      while ((p % i) == 0) {

        p = p / i;
      }
    }
  }

  if (p != 1) {

    ans++;
  }

  cout << ans;

  return 0;
}
Problem p02900 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "bits/stdc++.h"
#include <math.h>
#include <regex>
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define INF (INT_MAX / 2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX / 2)
const int MGN = 10;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using psi = pair<string, int>;

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

int prime_factors_num(ll n) {
  int res = 0;
  for (int p = 2; p * p <= n; p++) {
    // if (is_prime(p)) {
    if (n % p != 0)
      continue; // p is not n's devisor
    else {
      while (n % p == 0) {
        // fac[p]++;
        n /= p;
      }
      res++;
    }
  }
  if (n > 1)
    res++; // fac[n]++;
  return res;
}

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

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

  ll C = gcd(A, B);

  int ans = prime_factors_num(C) + 1;

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include "bits/stdc++.h"
#include <math.h>
#include <regex>
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define INF (INT_MAX / 2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX / 2)
const int MGN = 10;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using psi = pair<string, int>;

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

int prime_factors_num(ll n) {
  int res = 0;
  for (ll p = 2; p * p <= n; p++) {
    // if (is_prime(p)) {
    if (n % p != 0)
      continue; // p is not n's devisor
    else {
      while (n % p == 0) {
        // fac[p]++;
        n /= p;
      }
      res++;
    }
  }
  if (n > 1)
    res++; // fac[n]++;
  return res;
}

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

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

  ll C = gcd(A, B);

  int ans = prime_factors_num(C) + 1;

  cout << ans << endl;

  return 0;
}
Problem p02900 (C++)

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

// template
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(v) (v).begin(), (v).end()
typedef long long int ll;
typedef pair<ll, ll> P;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  fill((T *)array, (T *)(array + N), val);
}
const int inf = INT_MAX / 2;
const ll INF = LLONG_MAX / 2;
// template end

int main() {
  ll a, b;
  scanf("%lld%lld", &a, &b);
  ll g = __gcd(a, b);
  int cnt = 0;
  for (int i = 2; i * i <= g; i++) {
    if (g % i == 0) {
      cnt++;
      while (g % i == 0)
        g /= i;
    }
  }
  if (g != 1)
    cnt++;
  printf("%d\n", cnt + 1);
  return 0;
}

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

// template
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(v) (v).begin(), (v).end()
typedef long long int ll;
typedef pair<ll, ll> P;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  fill((T *)array, (T *)(array + N), val);
}
const int inf = INT_MAX / 2;
const ll INF = LLONG_MAX / 2;
// template end

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

Buggy submission (status: Time Limit Exceeded):
// #include <tourist>
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1},
          Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
// setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
struct edge {
  int to, cost;
};
ll a, b;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> a >> b;
  ll ans = 0;
  ll g = gcd(a, b);
  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 + 1 << "\n";
}


Fixed submission:
// #include <tourist>
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1},
          Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
// setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
struct edge {
  int to, cost;
};
ll a, b;

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

  cout << ans + 1 << "\n";
}
Problem p02900 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;
ll intpow(ll N, ll P) {
  if (P == 0)
    return 1;
  if (P % 2 == 0) {
    ll t = intpow(N, P / 2);
    return t * t;
  }
  return N * intpow(N, P - 1);
}
ll modpow(ll N, ll P, ll k) {
  if (P == 0)
    return 1;
  if (P % 2 == 0) {
    ll t = modpow(N, P / 2, k) % k;
    return t * t % k;
  }
  return N * modpow(N, P - 1, k) % k;
}
ll modkai(ll n, ll m, ll k) { // n*(n-1)*(n-2)*...(m+1)%k
  if (n == m)
    return 1;
  return modkai(n - 1, m, k) * n % k;
}
ll mod_cnb(ll n, ll m, ll k) { // nCm%k,kは十分大きい素数
  int m_ = modkai(m, 0, k);
  return modkai(n, n - m, k) * modpow(m_, k - 2, k) % k;
}
ll gcd(ll n, ll m) {
  int n_ = max(n, m);
  int m_ = min(n, m);
  if (n_ % m_ == 0)
    return m_;
  return gcd(m_, n_ % m_);
}
ll lcm(ll n, ll m) { return n * m / gcd(n, m); }
int main() {
  ll a, b;
  cin >> a >> b;
  ll g = gcd(a, b);
  ll G = g;
  vector<ll> v;
  for (ll i = 2; i * i <= G; i++) {
    if (g % i == 0) {
      v.push_back(1);
      g /= i;
    }
    while (g % i == 0) {
      v[v.size() - 1]++;
      g /= i;
    }
  }
  if (g > 1)
    v.push_back(1);
  cout << v.size() + 1 << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;
ll intpow(ll N, ll P) {
  if (P == 0)
    return 1;
  if (P % 2 == 0) {
    ll t = intpow(N, P / 2);
    return t * t;
  }
  return N * intpow(N, P - 1);
}
ll modpow(ll N, ll P, ll k) {
  if (P == 0)
    return 1;
  if (P % 2 == 0) {
    ll t = modpow(N, P / 2, k) % k;
    return t * t % k;
  }
  return N * modpow(N, P - 1, k) % k;
}
ll modkai(ll n, ll m, ll k) { // n*(n-1)*(n-2)*...(m+1)%k
  if (n == m)
    return 1;
  return modkai(n - 1, m, k) * n % k;
}
ll mod_cnb(ll n, ll m, ll k) { // nCm%k,kは十分大きい素数
  int m_ = modkai(m, 0, k);
  return modkai(n, n - m, k) * modpow(m_, k - 2, k) % k;
}
ll gcd(ll n, ll m) {
  ll n_ = max(n, m);
  ll m_ = min(n, m);
  if (n_ % m_ == 0)
    return m_;
  return gcd(m_, n_ % m_);
}
ll lcm(ll n, ll m) { return n * m / gcd(n, m); }
int main() {
  ll a, b;
  cin >> a >> b;
  ll g = gcd(a, b);
  ll G = g;
  vector<ll> v;
  for (ll i = 2; i * i <= G; i++) {
    if (g % i == 0) {
      v.push_back(1);
      g /= i;
    }
    while (g % i == 0) {
      v[v.size() - 1]++;
      g /= i;
    }
  }
  if (g > 1)
    v.push_back(1);
  cout << v.size() + 1 << endl;
  return 0;
}
Problem p02900 (C++)

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

using namespace std;

int main() {
  int64_t a, b;
  cin >> a >> b;
  int ans = 1;
  set<int64_t> set;
  auto n = min(a, b);
  auto m = max(a, b);
  for (int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      if (set.find(i) == set.end()) {
        if (m % i == 0)
          ans++;
        set.insert(i);
      }
      n /= i;
    }
  }
  if (n != 1 && m % n == 0)
    ++ans;
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <set>

using namespace std;

int main() {
  int64_t a, b;
  cin >> a >> b;
  int ans = 1;
  set<int64_t> set;
  auto n = min(a, b);
  auto m = max(a, b);
  for (int64_t i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      if (set.find(i) == set.end()) {
        if (m % i == 0)
          ans++;
        set.insert(i);
      }
      n /= i;
    }
  }
  if (n != 1 && m % n == 0)
    ++ans;
  cout << ans << endl;
  return 0;
}
Problem p02900 (C++)

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

using LL = int64_t;
using VL = vector<LL>;
using PLL = pair<LL, LL>;

template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

template <class T> std::map<T, int> factorize(T n) {
  std::map<T, int> res;
  for (int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n > 1)
    res[n]++;
  return res;
}

// main code
int main(int argc, char *argv[]) {
  LL a, b;
  cin >> a >> b;
  LL g = gcd(a, b);
  auto mp = factorize(g);
  cout << mp.size() + 1 << endl;
  return 0;
}


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

using LL = int64_t;
using VL = vector<LL>;
using PLL = pair<LL, LL>;

template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

template <class T> std::map<T, int> factorize(T n) {
  std::map<T, int> res;
  for (LL i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n > 1)
    res[n]++;
  return res;
}

// main code
int main(int argc, char *argv[]) {
  LL a, b;
  cin >> a >> b;
  LL g = gcd(a, b);
  auto mp = factorize(g);
  cout << mp.size() + 1 << endl;
  return 0;
}
Problem p02900 (C++)

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

using namespace std;
using ll = long long;

int main() {
  ll A, B;
  cin >> A >> B;
  ll g = __gcd(A, B);

  int ans = 1;
  if (g % 2 == 0) {
    ans++;
    while (g % 2 == 0)
      g >> 1;
  }
  for (ll p = 3; p <= sqrt(g); p += 2) {
    if (g % p == 0) {
      ans++;
      while (g % p == 0)
        g /= p;
    }
  }
  if (g > 2)
    ans++;
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include "bits/stdc++.h"

using namespace std;
using ll = long long;

int main() {
  ll A, B;
  cin >> A >> B;
  ll g = __gcd(A, B);

  int ans = 1;
  if (g % 2 == 0) {
    ans++;
    while (g % 2 == 0)
      g >>= 1;
  }
  for (ll p = 3; p <= sqrt(g); p += 2) {
    if (g % p == 0) {
      ans++;
      while (g % p == 0)
        g /= p;
    }
  }
  if (g > 2)
    ans++;
  cout << ans << endl;
  return 0;
}