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

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

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;
typedef long long ll;

void factprime(long long x, std::set<long long> &st) {
  long long i = 2;
  long long cur = x;
  // map<long long, long long> tmp;

  while (cur >= 2) {
    for (long long i = 2; i < cur; i++) {
      if (i * i > cur) {
        st.insert(cur);
        return;
      }
      if (cur % i == 0) {
        cur = cur / i;
        // tmp[i]++;
        st.insert(i);
        break;
      }
    }
  }
  // primefact[x] = tmp;
}

int main(void) {
  ll a, b;
  cin >> a >> b;
  std::set<long long> sta;
  std::set<long long> stb;
  factprime(a, sta);
  factprime(b, stb);
  // cout << sta << stb << endl;
  auto itra = sta.begin();
  auto itrb = stb.begin();
  long long ans = 1;
  for (; itra != sta.end() && itrb != stb.end();) {
    if (*itra == *itrb) {
      ans++;
      itra++;
      itrb++;
    } else if (*itra > *itrb) {
      itrb++;
    } else {
      itra++;
      /* code */
    }
  }
  cout << ans << "\n";
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <vector>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;
typedef long long ll;

void factprime(long long x, std::set<long long> &st) {
  long long i = 2;
  long long cur = x;
  // map<long long, long long> tmp;

  while (cur >= 2) {
    for (long long i = 2;; i++) {
      if (i * i > cur) {
        st.insert(cur);
        return;
      }
      if (cur % i == 0) {
        cur = cur / i;
        // tmp[i]++;
        st.insert(i);
        break;
      }
    }
  }
  // primefact[x] = tmp;
}

int main(void) {
  ll a, b;
  cin >> a >> b;
  std::set<long long> sta;
  std::set<long long> stb;
  factprime(a, sta);
  factprime(b, stb);
  // cout << sta << stb << endl;
  auto itra = sta.begin();
  auto itrb = stb.begin();
  long long ans = 1;
  for (; itra != sta.end() && itrb != stb.end();) {
    if (*itra == *itrb) {
      ans++;
      itra++;
      itrb++;
    } else if (*itra > *itrb) {
      itrb++;
    } else {
      itra++;
      /* code */
    }
  }
  cout << ans << "\n";
}
Problem p02900 (C++)

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

int main() {
  ll a, b, r, tmp;
  cin >> a >> b;
  if (a < b) {
    tmp = a;
    a = b;
    b = tmp;
  }
  r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  int ans = 0;
  for (int i = 2; i * i <= b; i++) {
    bool flag = 0;
    while (b % i == 0) {
      flag = 1;
      b /= i;
    }
    if (flag == 1)
      ans++;
  }
  if (b != 1)
    ans++;
  cout << ans + 1 << 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;

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

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

#define REP(i, l, n) for (int i = (l), i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define pb push_back

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

int main() {
  ll a, b;
  cin >> a >> b;
  int i = 2;
  map<ll, ll> mp1, mp2;
  mp1[1] = 1;
  mp2[1] = 1;
  while (a >= i * i) {
    if (a % i == 0) {
      mp1[i]++;
      a /= i;
    } else {
      i++;
    }
  }
  mp1[a]++;
  i = 2;
  while (b >= i * i) {
    if (b % i == 0) {
      mp2[i]++;
      b /= i;
    } else {
      i++;
    }
  }
  mp2[b]++;
  ll ans = 0;
  for (auto &x : mp1) {
    if (mp2[x.first] != 0) {
      ans++;
    }
  }
  cout << ans << endl;
}

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

#define REP(i, l, n) for (int i = (l), i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define pb push_back

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

int main() {
  ll a, b;
  cin >> a >> b;
  ll i = 2;
  map<ll, ll> mp1, mp2;
  mp1[1] = 1;
  mp2[1] = 1;
  while (a >= i * i) {
    if (a % i == 0) {
      mp1[i]++;
      a /= i;
    } else {
      i++;
    }
  }
  mp1[a]++;
  i = 2;
  while (b >= i * i) {
    if (b % i == 0) {
      mp2[i]++;
      b /= i;
    } else {
      i++;
    }
  }
  mp2[b]++;
  ll ans = 0;
  for (auto &x : mp1) {
    if (mp2[x.first] != 0) {
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p02900 (C++)

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

using namespace std;

const int MOD = 1e9 + 7;
const int N = 1e5;
const long long INF = 1e9;

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


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

using namespace std;

const int MOD = 1e9 + 7;
const int N = 1e5;
const long long INF = 1e9;

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

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

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

int main() {
  long long a, b;
  cin >> a >> b;
  long long ans = 1;
  ll g = gcd(a, b);
  for (int i = 2; 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>
#include <iostream>
#include <math.h>
#include <numeric>
using namespace std;
#define ll long long

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

int main() {
  long long a, b;
  cin >> a >> b;
  long long ans = 1;
  ll g = gcd(a, b);
  for (int i = 2; i <= sqrt(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 <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

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

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

Fixed submission:
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

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

int main() {
  ll a, b;
  cin >> a >> b;
  ll G = gcd(a, b);
  ll ans = 0;
  ll g = gcd(a, b);
  for (ll i = 2; i * i <= G; i++) {
    if (g % i == 0) {
      while (g % i == 0)
        g /= i;
      ans++;
    }
  }
  if (g != 1)
    ans++;
  cout << ans + 1 << endl;
}
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;
  if (a < b)
    swap(a, b);
  long long amari;
  long long waru = b;
  long long warareru = a;

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

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

int main() {
  long long a, b;
  cin >> a >> b;
  if (a < b)
    swap(a, b);
  long long amari;
  long long waru = b;
  long long warareru = a;

  while (amari != 0) {
    amari = warareru % waru;
    if (amari == 0)
      break;
    warareru = waru;
    waru = amari;
  }
  long long gcd = waru;
  int ans = 0;
  for (long long i = 2; i * i <= gcd; i++) {
    if (gcd % i == 0) {
      ans++;
      while (gcd % i == 0)
        gcd /= i;
    }
  }
  if (gcd != 1)
    ans++;
  ans++;
  cout << ans;
}
Problem p02900 (C++)

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

using namespace std;

using ll = long long;

const long long MOD = 1e9 + 7;
const int INF = 1e9 + 7;

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll A, B;
  cin >> A >> B;
  ll g = gcd(A, B);
  vector<bool> prime(1e6 + 1, true);
  prime[0] = prime[1] = false;
  for (ll i = 2; i * i <= g; ++i) {
    for (ll j = i * i; j <= 1e6; j += i) {
      prime[j] = false;
    }
  }
  ll ans = 0;
  ll x = g;
  int i = 2;
  while (x > 1) {
    while (i * i <= g && !prime[i]) {
      ++i;
    }
    if (i * i > g) {
      ++ans;
      break;
    }
    if (x % i == 0) {
      ++ans;
      while (x % i == 0)
        x /= i;
    }

    ++i;
  }
  ++ans;
  cout << ans << endl;
}

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

using namespace std;

using ll = long long;

const long long MOD = 1e9 + 7;
const int INF = 1e9 + 7;

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll A, B;
  cin >> A >> B;
  ll g = gcd(A, B);
  vector<bool> prime(1e6 + 1, true);
  prime[0] = prime[1] = false;
  for (ll i = 2; i * i <= g; ++i) {
    for (ll j = i * i; j <= 1e6; j += i) {
      prime[j] = false;
    }
  }
  ll ans = 0;
  ll x = g;
  ll i = 2;
  while (x > 1) {
    while (i * i <= g && !prime[i]) {
      ++i;
    }
    if (i * i > g) {
      ++ans;
      break;
    }
    if (x % i == 0) {
      ++ans;
      while (x % i == 0)
        x /= i;
    }

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>

using namespace std;

/* -----------------------------------------------------------------------------
        型とクラス定義
----------------------------------------------------------------------------- */
typedef long long ll;

/* -----------------------------------------------------------------------------
        大域データ
----------------------------------------------------------------------------- */
ll A, B, R, C;

int main() {

  int cnt = 1;

  // 2２つの正整数の読込み
  scanf("%d %d", &A, &B);

  while ((R = A % B) > 0) {
    A = B;
    B = R;
  }
  C = B;

  // 初期状態の満足度
  for (int i = 2; i <= C && i <= 1000000; i++) {
    if (C % i == 0) {
      cnt++;
      while (C % i == 0)
        C /= i;
    }
  }
  cnt += (C > 1);

  printf("%d\n", cnt);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>

using namespace std;

/* -----------------------------------------------------------------------------
        型とクラス定義
----------------------------------------------------------------------------- */
typedef long long ll;

/* -----------------------------------------------------------------------------
        大域データ
----------------------------------------------------------------------------- */
ll A, B, R, C;

int main() {

  int cnt = 1;

  // 2２つの正整数の読込み
  scanf("%lld %lld", &A, &B);

  while ((R = A % B) > 0) {
    A = B;
    B = R;
  }
  C = B;

  // 初期状態の満足度
  for (int i = 2; i <= C && i <= 1000000; i++) {
    if (C % i == 0) {
      cnt++;
      while (C % i == 0)
        C /= i;
    }
  }
  cnt += (C > 1);

  printf("%d\n", cnt);
  return 0;
}
Problem p02900 (C++)

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

#define ll long long

using namespace std;

int main(void) {
  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 << "\n";
  return 0;
}

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

#define ll long long

using namespace std;

int main(void) {
  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 << "\n";
  return 0;
}
Problem p02900 (C++)

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define RITR(x, c) for (__typeof(c.rbegin()) x = c.rbegin(); x != c.rend(); x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll, ll>
#define pi pair<int, int>

#define all(a) (a.begin()), (a.end())
#define rall(a) (a.rbegin()), (a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a, b;
  cin >> a >> b;
  ll g = __gcd(a, b);

  int ans = 0;
  for (int i = 2; i * i <= g; i++) {
    if (g % i == 0) {
      while (g % i == 0)
        g /= i;
      ans++;
    }
  }
  if (g != 1)
    ans++;
  cout << ans + 1 << "\n";
  return 0;
}

// g = __gcd(a, b)としてgを素因数分解
// 素因数の種類数+1


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define RITR(x, c) for (__typeof(c.rbegin()) x = c.rbegin(); x != c.rend(); x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll, ll>
#define pi pair<int, int>

#define all(a) (a.begin()), (a.end())
#define rall(a) (a.rbegin()), (a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a, b;
  cin >> a >> b;
  ll g = __gcd(a, b);

  int ans = 0;
  for (ll i = 2; i * i <= g; i++) {
    if (g % i == 0) {
      while (g % i == 0)
        g /= i;
      ans++;
    }
  }
  if (g != 1)
    ans++;
  cout << ans + 1 << "\n";
  return 0;
}

// g = __gcd(a, b)としてgを素因数分解
// 素因数の種類数+1
Problem p02900 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define lli long long int
#define lower(a) transform(a.begin(), a.end(), a.begin(), ::tolower);

using namespace std;

const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353;
const long long inf = 1LL << 57;
const int M = 1e6 + 500;
const lli ths = 1LL << 40;

void solve() {
  lli a, b;
  cin >> a >> b;
  lli x = __gcd(a, b);
  lli ans = 0;
  bool ok = 0;
  for (int i = 2; i * i <= x; i++) {
    ok = 0;
    while (x % i == 0) {
      x /= i;
      ok = 1;
    }
    ans += ok;
  }
  ans++;
  ans += (x > 1);
  cout << ans;
  return;
}
/*
7
6 7 4 1 2 11 6
5
1 2 10 4 5
*/

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

  lli t;
  t = 1;
  //    cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define lli long long int
#define lower(a) transform(a.begin(), a.end(), a.begin(), ::tolower);

using namespace std;

const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353;
const long long inf = 1LL << 57;
const int M = 1e6 + 500;
const lli ths = 1LL << 40;

void solve() {
  lli a, b;
  cin >> a >> b;
  lli x = __gcd(a, b);
  lli ans = 0;
  bool ok = 0;
  for (lli i = 2; i * i <= x; i++) {
    ok = 0;
    while (x % i == 0) {
      x /= i;
      ok = 1;
    }
    ans += ok;
  }
  ans++;
  ans += (x > 1);
  cout << ans;
  return;
}
/*
7
6 7 4 1 2 11 6
5
1 2 10 4 5
*/

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

  lli t;
  t = 1;
  //    cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}
Problem p02900 (C++)

Buggy submission (status: Runtime Error):
// This code writed by chtholly_micromaker(MicroMaker)
#include <bits/stdc++.h>
#define reg register
#define int long long
using namespace std;
template <class t> inline void rd(t &s) {
  s = 0;
  reg char c = getchar();
  while (!isdigit(c))
    c = getchar();
  while (isdigit(c))
    s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();
  return;
}
bool vis[1000000000];
inline bool isprime(int x) {
  if (x == 1)
    return false;
  reg int maxi = sqrt(x);
  for (int i = 2; i <= maxi; ++i)
    if (!(x % i))
      return false;
  return true;
}
signed main(void) {
  int n, m;
  cin >> n >> m;
  int g = __gcd(n, m);
  reg int maxi = sqrt(g);
  reg int ans = 0;
  //	cout<<g<<endl;
  for (int i = 1; i <= maxi; ++i)
    if (!(g % i)) {
      if (isprime(i))
        ++ans;
      else
        vis[i] = true;
      if (i * i != g) {
        if (isprime(g / i))
          ++ans;
        //				else
        //					vis[g/i]=true;
      }
    }
  for (int i = 2; i <= maxi; ++i) {
    if (vis[i] && i * i != g)
      ++ans; //,cout<<"passed "<<i<<endl;
    for (int j = 1; i * j <= g; ++j)
      vis[i * j] = false;
  }
  cout << ans + 1 << endl;
  return 0;
}


Fixed submission:
// This code writed by chtholly_micromaker(MicroMaker)
#include <bits/stdc++.h>
#define reg register
#define int long long
using namespace std;
template <class t> inline void rd(t &s) {
  s = 0;
  reg char c = getchar();
  while (!isdigit(c))
    c = getchar();
  while (isdigit(c))
    s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();
  return;
}
bool vis[1000000000];
inline bool isprime(int x) {
  if (x == 1)
    return false;
  reg int maxi = sqrt(x);
  for (int i = 2; i <= maxi; ++i)
    if (!(x % i))
      return false;
  return true;
}
signed main(void) {
  int n, m;
  cin >> n >> m;
  int g = __gcd(n, m);
  reg int maxi = sqrt(g);
  reg int ans = 0;
  //	cout<<g<<endl;
  for (int i = 1; i <= maxi; ++i)
    if (!(g % i)) {
      if (isprime(i))
        ++ans;
      else
        vis[i] = true;
      if (i * i != g) {
        if (isprime(g / i))
          ++ans;
        //				else
        //					vis[g/i]=true;
      }
    }
  for (int i = 2; i <= maxi; ++i) {
    if (vis[i] && i * i != g)
      ++ans; //,cout<<"passed "<<i<<endl;
    for (int j = 1; i * j <= maxi; ++j)
      vis[i * j] = false;
  }
  cout << ans + 1 << endl;
  return 0;
}
Problem p02900 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define LL long long
LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
int main() {
  LL a, b, c;
  int ans = 1;
  scanf("%lld%lld", &a, &b);
  c = gcd(a, b);
  for (int i = 2; i * i <= c; i++) {
    if (c % i == 0)
      ans++;
    while (c % i == 0)
      c /= i;
  }
  printf("%d", ans + (c > 1));
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define LL long long
LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
int main() {
  LL a, b, c;
  int ans = 1;
  scanf("%lld%lld", &a, &b);
  c = gcd(a, b);
  for (LL i = 2; i * i <= c; i++) {
    if (c % i == 0)
      ans++;
    while (c % i == 0)
      c /= i;
  }
  printf("%d", ans + (c > 1));
  return 0;
}
Problem p02900 (C++)

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

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 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;
}


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

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 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;
}
Problem p02900 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define INF 1000000000000000000
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define x first
#define y second
const int maxx = 1000006;
const int maxlog = 20;
const ll mod = 1000000007;
int arr[maxx];

int main() {
  IOS ll a, b;
  cin >> a >> b;
  ll g = __gcd(a, b);
  vector<ll> v;
  for (int i = 2; i * i <= g; i++) {
    if (g % i == 0) {
      while (g % i == 0)
        g /= i;
      v.pb(i);
    }
  }
  if (g > 1)
    v.pb(g);
  ll count = 0;
  count = v.size();
  cout << count + 1;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define INF 1000000000000000000
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define x first
#define y second
const int maxx = 1000006;
const int maxlog = 20;
const ll mod = 1000000007;
int arr[maxx];

int main() {
  IOS ll a, b;
  cin >> a >> b;
  ll g = __gcd(a, b);
  vector<ll> v;
  for (ll i = 2; i * i <= g; i++) {
    if (g % i == 0) {
      while (g % i == 0)
        g /= i;
      v.pb(i);
    }
  }
  if (g > 1)
    v.pb(g);
  ll count = 0;
  count = v.size();
  cout << count + 1;
}
Problem p02900 (C++)

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

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

int main() {
  ll a, b;
  cin >> a >> b;
  ll g = __gcd(a, b);
  cout << countPrimes(g) + 1 << endl;
}

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

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

int main() {
  ll a, b;
  cin >> a >> b;
  ll g = __gcd(a, b);
  cout << countPrimes(g) + 1 << endl;
}
Problem p02900 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
#define all(x) (x).begin(), (x).end()
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;
}
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;

map<ll, ll> prime_factor(ll N) {
  map<ll, ll> prime;
  for (int i = 2; i * i <= N; i++) {
    while (N % i == 0) {
      prime[i]++;
      N /= i;
    }
  }

  if (N != 1)
    prime[N] = 1;
  return prime;
}
int main() {
  ll A, B;
  cin >> A >> B;

  map<ll, ll> mpA = prime_factor(A);
  map<ll, ll> mpB = prime_factor(B);

  int ans = 1;
  for (auto itr : mpA) {
    if (mpB.count(itr.first))
      ans++;
  }

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

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
#define all(x) (x).begin(), (x).end()
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;
}
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;

map<ll, ll> prime_factor(ll N) {
  map<ll, ll> prime;
  for (ll i = 2; i * i <= N; i++) {
    while (N % i == 0) {
      prime[i]++;
      N /= i;
    }
  }

  if (N != 1)
    prime[N] = 1;
  return prime;
}
int main() {
  ll A, B;
  cin >> A >> B;

  map<ll, ll> mpA = prime_factor(A);
  map<ll, ll> mpB = prime_factor(B);

  int ans = 1;
  for (auto itr : mpA) {
    if (mpB.count(itr.first))
      ans++;
  }

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

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

#define int long long
#define hell 1000000007
#define endl "\n"
#define io                                                                     \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define MAX_SIZE 1000000

int32_t main() {
  io int a, b;
  cin >> a >> b;

  int gcd = __gcd(a, b);

  int gcd1 = gcd;
  int count = 1;

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

  (gcd > 1) ? cout << count + 1 : cout << count;

  return 0;
}

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

#define int long long
#define hell 1000000007
#define endl "\n"
#define io                                                                     \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define MAX_SIZE 1000000

int32_t main() {
  io int a, b;
  cin >> a >> b;

  int gcd = __gcd(a, b);

  int gcd1 = gcd;
  int count = 1;

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

  (gcd > 1) ? cout << count + 1 : cout << count;

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

int main() {
  long long a, b, g, buf;
  set<long long> cd;
  cin >> a >> b;
  g = gcd(a, b);

  buf = g;
  for (int i = 2; i * i <= g; i++) {
    if (buf % i == 0) {
      cd.insert(i);
      while (buf % i == 0)
        buf /= i;
    }
  }
  if (buf != 1)
    cd.insert(buf);
  cd.insert(1);

  cout << cd.size() << endl;
}

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

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

int main() {
  long long a, b, g, buf;
  set<long long> cd;
  cin >> a >> b;
  g = gcd(a, b);

  buf = g;
  for (long long i = 2; i * i <= g; i++) {
    if (buf % i == 0) {
      cd.insert(i);
      while (buf % i == 0)
        buf /= i;
    }
  }
  if (buf != 1)
    cd.insert(buf);
  cd.insert(1);

  cout << cd.size() << endl;
}
Problem p02900 (C++)

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

long gcd(long x, long y) {
  long r;
  if (x < y)
    swap(x, y);

  while (y > 0) {
    r = x % y;
    x = y;
    y = r;
  }
  return x;
}

long CntPrime(long x) {
  long cnt = 0;
  if (x < 2) {
    // cout << "CntPrimt(1)" << x << endl;
    return 0;
  } else if (x == 2)
    return 1;
  else if (x % 2 == 0) {
    long y = 0;
    while (y == 0 && x != 1) {
      y = x % 2;
      x = x / 2;
    }
    if (y != 0)
      x = 2 * x + y;
    // cout << "CntPrimt(2)" << x << endl;
    cnt++;
    cnt += CntPrime(x);
    return cnt;
  } else {
    for (long i = 3; i <= x; i += 2) {
      if (x % i == 0) {
        long y = 0;
        while (y == 0 && x != 1) {
          y = x % i;
          x = x / i;
        }
        if (y != 0)
          x = x * i + y;
        // cout << "CntPrimt(" << i << ")" <<  x << endl;
        cnt++;
        cnt += CntPrime(x);
        return cnt;
      }
    }
  }
  // return cnt;
}

int main() {

  long A, B;
  cin >> A >> B;

  long num = gcd(A, B);
  // cout << num << endl;
  long cnt = CntPrime(num);

  cout << cnt + 1;

  return 0;
}

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

long gcd(long x, long y) {
  long r;
  if (x < y)
    swap(x, y);

  while (y > 0) {
    r = x % y;
    x = y;
    y = r;
  }
  return x;
}

long CntPrime(long x) {
  long cnt = 0;
  if (x < 2) {
    // cout << "CntPrimt(1)" << x << endl;
    return 0;
  } else if (x == 2)
    return 1;
  else if (x % 2 == 0) {
    long y = 0;
    while (y == 0 && x != 1) {
      y = x % 2;
      x = x / 2;
    }
    if (y != 0)
      x = 2 * x + y;
    // cout << "CntPrimt(2)" << x << endl;
    cnt++;
    cnt += CntPrime(x);
    return cnt;
  } else {
    for (long i = 3; i <= x; i += 2) {
      if (x % i == 0) {
        long y = 0;
        while (y == 0 && x != 1) {
          y = x % i;
          x = x / i;
        }
        if (y != 0)
          x = x * i + y;
        // cout << "CntPrimt(" << i << ")" <<  x << endl;
        cnt++;
        cnt += CntPrime(x);
        return cnt;
      } else if (i * i > x) {
        return 1;
      }
    }
  }
  // return cnt;
}

int main() {

  long A, B;
  cin >> A >> B;

  long num = gcd(A, B);
  // cout << num << endl;
  long cnt = CntPrime(num);

  cout << cnt + 1;

  return 0;
}
Problem p02900 (C++)

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

using namespace std;

long long f(long long a, long long b) { return !b ? a : f(b, a % b); }

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

int main() {
  long long a, b, cnt = 0;
  scanf("%lld%lld", &a, &b);
  long long c = a > b ? f(a, b) : f(b, a);
  if (c == 1) {
    printf("1");
    return 0;
  }
  for (long long i = 1; i * i <= c; i++) {
    if (isPrime(i) && c % i == 0)
      ++cnt;
    if (isPrime(c / i) && c % i == 0 && c / i != i)
      ++cnt;
  }
  printf("%lld", cnt);
  return 0;
}

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

using namespace std;

long long f(long long a, long long b) { return !b ? a : f(b, a % b); }

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

int main() {
  long long a, b, cnt = 0;
  scanf("%lld%lld", &a, &b);
  long long c = a > b ? f(a, b) : f(b, a);
  if (c == 1) {
    printf("1");
    return 0;
  }
  for (long long i = 1; i * i <= c; i++) {
    if (c % i == 0) {
      if (isPrime(i))
        cnt++;
      if (isPrime(c / i) && i != c / i)
        cnt++;
    }
  }
  printf("%lld", cnt);
  return 0;
}
Problem p02900 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll a, b;
  cin >> a >> b;
  ll cnt = 0, g = __gcd(a, b);
  for (int i = 2; i * i <= g; i++) {
    if (g % i != 0)
      continue;
    cnt++;
    while (g % i == 0)
      g /= i;
  }
  if (g != 1)
    cnt++;
  cout << cnt + 1 << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll a, b;
  cin >> a >> b;
  ll cnt = 0, g = __gcd(a, b);
  for (ll i = 2; i * i <= g; i++) {
    if (g % i != 0)
      continue;
    cnt++;
    while (g % i == 0)
      g /= i;
  }
  if (g != 1)
    cnt++;
  cout << cnt + 1 << endl;
  return 0;
}
Problem p02900 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define eps 1e-9
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LLP;
const int MAXN = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;
const int LOGN = 20;
int arr[MAXN];
int ans[MAXN];
bool isprime(ll tmp) {
  for (ll i = 2; i * i <= tmp; ++i) {
    if (tmp % i == 0)
      return false;
  }
  return tmp != 1;
}
signed main() {
  ll a, b;
  scanf("%lld%lld", &a, &b);
  ll gcd = __gcd(a, b);
  int cnt = 0;
  if (isprime(gcd)) {
    puts("2");
    return 0;
  }
  for (ll i = 2; gcd != 1; ++i) {
    if (gcd % i == 0) {
      cnt++;
      while (gcd % i == 0)
        gcd /= i;
    }
  }
  printf("%d\n", cnt + 1);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define eps 1e-9
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LLP;
const int MAXN = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;
const int LOGN = 20;
int arr[MAXN];
int ans[MAXN];
bool isprime(ll tmp) {
  for (ll i = 2; i * i <= tmp; ++i) {
    if (tmp % i == 0)
      return false;
  }
  return tmp != 1;
}
signed main() {
  ll a, b;
  scanf("%lld%lld", &a, &b);
  ll gcd = __gcd(a, b);
  int cnt = 0;
  if (isprime(gcd)) {
    puts("2");
    return 0;
  }
  for (ll i = 2; gcd != 1; ++i) {
    if (gcd % i == 0) {
      cnt++;
      while (gcd % i == 0)
        gcd /= i;
      if (isprime(gcd)) {
        cnt++;
        break;
      }
    }
  }
  printf("%d\n", cnt + 1);
  return 0;
}
Problem p02900 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif // LOCAL
using ll = long long;
ll a, b, x;

int main() {
  scanf("%lld %lld", &a, &b);
  x = __gcd(a, b);
  int ans = 1;
  for (int i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      ans++;
      while (x % i == 0)
        x /= i;
    }
    if (x == 1)
      break;
  }
  if (x > 1)
    ++ans;
  printf("%d\n", ans);
}
/*
    Good Luck
        -Lucina
*/


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif // LOCAL
using ll = long long;
ll a, b, x;

int main() {
  scanf("%lld %lld", &a, &b);
  x = __gcd(a, b);
  int ans = 1;
  for (ll i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      ans++;
      while (x % i == 0)
        x /= i;
    }
    if (x == 1)
      break;
  }
  if (x > 1)
    ++ans;
  printf("%d\n", ans);
}
/*
    Good Luck
        -Lucina
*/
Problem p02900 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#define ll long long
#define itn int
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FFOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FFOR(i, 1, n)
#define SORT(V) sort((V).begin(), (V).end())
#define REVERSE(V) reverse((V).begin(), (V).end())
#define INF ((1LL << 62) - (1LL << 31))
#define MOD 1000000007
using namespace std;

ll N, M, K, A, B, C, ans = 0, cnt = 0;
string S, T;
vector<int> P, Q;
vector<pair<int, int>> PP;
bool CAN = false, CAN2 = true;

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

int main() {
  cin >> A >> B;
  N = gcd(A, B);

  if (N == 1) {
    cout << 1 << endl;
    return 0;
  }

  for (ll i = 2; i <= N; ++i) {
    while (N % i == 0) {
      N /= i;
      CAN = true;
    }
    if (CAN) {
      ans++;
      CAN = false;
      CAN2 = false;
    }
    if ((i * i >= N && CAN2 == true) || N == 1)
      break;
  }

  if (CAN2) {
    cout << 2 << endl; // Nが素数
    return 0;
  }
  cout << ans + 1 << endl;
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#define ll long long
#define itn int
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FFOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FFOR(i, 1, n)
#define SORT(V) sort((V).begin(), (V).end())
#define REVERSE(V) reverse((V).begin(), (V).end())
#define INF ((1LL << 62) - (1LL << 31))
#define MOD 1000000007
using namespace std;

ll N, M, K, A, B, C, ans = 0, cnt = 0;
string S, T;
vector<int> P, Q;
vector<pair<int, int>> PP;
bool CAN = false, CAN2 = true;

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

int main() {
  cin >> A >> B;
  N = gcd(A, B);

  if (N == 1) {
    cout << 1 << endl;
    return 0;
  }

  for (ll i = 2; i <= N; ++i) {
    while (N % i == 0) {
      N /= i;
      CAN = true;
    }
    if (CAN) {
      ans++;
      CAN = false;
      CAN2 = false;
    }
    if (i * i > N) {
      if (N != 1)
        ans++;
      break;
    }
    if (N == 1)
      break;
  }

  if (CAN2) {
    cout << 2 << endl; // Nが素数
    return 0;
  }
  cout << ans + 1 << endl;
}
Problem p02900 (C++)

Buggy submission (status: Time Limit Exceeded):
//
//  Disjoint Set of Common Divisors.cpp
//  National Olympiad in Informatics in Provinces
//
//  Created by 黄子齐 on 2019/9/28.
//  Copyright © 2019 黄子齐. All rights reserved.
//

#include <stdio.h>
#define ll long long
ll a, b;
ll gcd(ll x, ll y) {
  if (!y)
    return x;
  return gcd(y, x % y);
}
int main() {
  //    freopen("mytestdata.in", "r", stdin);
  scanf("%lld%lld", &a, &b);
  //    printf("%lld\n", gcd(a, b));
  ll x = gcd(a, b);
  ll sum = 0;
  for (int i = 2; i * i <= x; i++) {
    if (!(x % i)) {
      sum++;
      while (!(x % i)) {
        x /= i;
      }
    }
  }
  if (x > 1) {
    sum++;
  }
  printf("%lld\n", sum + 1);
  return 0;
}


Fixed submission:
//
//  Disjoint Set of Common Divisors.cpp
//  National Olympiad in Informatics in Provinces
//
//  Created by 黄子齐 on 2019/9/28.
//  Copyright © 2019 黄子齐. All rights reserved.
//

#include <stdio.h>
#define ll long long
ll a, b;
ll gcd(ll x, ll y) {
  if (!y)
    return x;
  return gcd(y, x % y);
}
int main() {
  //    freopen("mytestdata.in", "r", stdin);
  scanf("%lld%lld", &a, &b);
  //    printf("%lld\n", gcd(a, b));
  ll x = gcd(a, b);
  ll sum = 0;
  for (ll i = 2; i * i <= x; i++) {
    if (!(x % i)) {
      sum++;
      while (!(x % i)) {
        x /= i;
      }
    }
  }
  if (x > 1) {
    sum++;
  }
  printf("%lld\n", sum + 1);
  return 0;
}
Problem p02900 (C++)

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

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
map<ll, ll> prime_factor(ll N) {
  map<ll, ll> res; // res[2] = 4は、素因数2が4個あることを表す
  for (int i = 2; i * i <= N; i++) { // 小さい素因数から順に割っていく
    while (N % i == 0) { // i = 2が素因数だとすると、割り切れる限り2で割る
      res[i]++; // 割り切れる回数をres[i]に格納
      N /= i;
    }
  }
  if (N != 1)
    res[N] = 1; // ループ処理の結果、nが素数の場合、res[n] = 1とする。
  return res;
}
/*
 */
int main() {
  ll A, B;
  cin >> A >> B;
  ll g = gcd(A, B);

  map<ll, ll> ma = prime_factor(g); // gの素因数とその個数を収納
  ll count = 0;
  // Keyの値が小さい順にループ
  /*for (auto p : ma) {
    auto key = p.first;
    auto value = p.second;
    // key, valueを使う
    if(value >= 1) count++;//素因数の個数が１以上のものをカウント
  }*/
  cout << ma.size() + 1 << endl;
}

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

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
map<ll, ll> prime_factor(ll N) {
  map<ll, ll> res; // res[2] = 4は、素因数2が4個あることを表す
  for (ll i = 2; i * i <= N; i++) { // 小さい素因数から順に割っていく
    while (N % i == 0) { // i = 2が素因数だとすると、割り切れる限り2で割る
      res[i]++; // 割り切れる回数をres[i]に格納
      N /= i;
    }
  }
  if (N != 1)
    res[N] = 1; // ループ処理の結果、nが素数の場合、res[n] = 1とする。
  return res;
}
/*
 */
int main() {
  ll A, B;
  cin >> A >> B;
  ll g = gcd(A, B);

  map<ll, ll> ma = prime_factor(g); // gの素因数とその個数を収納
  ll count = 0;
  // Keyの値が小さい順にループ
  /*for (auto p : ma) {
    auto key = p.first;
    auto value = p.second;
    // key, valueを使う
    if(value >= 1) count++;//素因数の個数が１以上のものをカウント
  }*/
  cout << ma.size() + 1 << endl;
}
Problem p02900 (C++)

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

using namespace std;

// MACROS

#define ll long long
#define ull unsigned long long
#define ld long double

#define vi vector<int>
#define vll vector<ll>
#define vld vector<ld>
#define u_s unordered_set

#define pii pair<int, int>
#define pll pair<ll, ll>

#define FOR(i, n) for (ll(i) = 0; i < n; i++)
#define FORN(i, a, b) for (ll(i) = a; i < b; i++)
#define FORE(i, l) for (auto(i) : l)

#define pb push_back
#define pob pop_back
#define emp emplace
#define fi first
#define se second

#define all(n) (n).begin(), (n).end()
#define in(n) cin >> (n);
#define debug(n) cout << #n << ": " << n << '\n';

// FUNCTIONS

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

template <typename T> inline T ext_gcd(T a, T b, T &x, T &y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  T x1, y1;
  T g = ext_gcd(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return g;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  // cout << setprecision(15);
  ll a, b;
  cin >> a >> b;
  ll c = gcd(a, b);
  vll sieve(c + 1);
  set<ll> list;
  while (c > 0) {
    ll prev_c = c;
    for (ll i = 2; i * i <= c; i++) {
      if (c % i == 0) {
        list.emp(i);
        c /= i;
        break;
      }
    }
    if (c == prev_c)
      break;
  }
  if (c > 0)
    list.emp(c);
  list.emp(1);
  cout << list.size() << '\n';
}


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

using namespace std;

// MACROS

#define ll long long
#define ull unsigned long long
#define ld long double

#define vi vector<int>
#define vll vector<ll>
#define vld vector<ld>
#define u_s unordered_set

#define pii pair<int, int>
#define pll pair<ll, ll>

#define FOR(i, n) for (ll(i) = 0; i < n; i++)
#define FORN(i, a, b) for (ll(i) = a; i < b; i++)
#define FORE(i, l) for (auto(i) : l)

#define pb push_back
#define pob pop_back
#define emp emplace
#define fi first
#define se second

#define all(n) (n).begin(), (n).end()
#define in(n) cin >> (n);
#define debug(n) cout << #n << ": " << n << '\n';

// FUNCTIONS

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

template <typename T> inline T ext_gcd(T a, T b, T &x, T &y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  T x1, y1;
  T g = ext_gcd(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return g;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  // cout << setprecision(15);
  ll a, b;
  cin >> a >> b;
  ll c = gcd(a, b);
  set<ll> list;
  while (c > 0) {
    ll prev_c = c;
    for (ll i = 2; i * i <= c; i++) {
      if (c % i == 0) {
        list.emp(i);
        c /= i;
        break;
      }
    }
    if (c == prev_c)
      break;
  }
  if (c > 0)
    list.emp(c);
  list.emp(1);
  cout << list.size() << '\n';
}
Problem p02900 (C++)

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

using namespace std;

map<long long, int> factorize(long long n) {
  map<long long, int> m;
  for (long long x = 2; x <= n; ++x) {
    while (n % x == 0) {
      ++m[x];
      n /= x;
    }
  }
  if (n != 1) {
    ++m[n];
  }
  return m;
}

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

int main() {
  long long A, B;
  cin >> A >> B;
  auto d = gcd(A, B);
  auto ans = factorize(d).size() + 1;
  cout << ans << endl;
}


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

using namespace std;

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

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

int main() {
  long long A, B;
  cin >> A >> B;
  auto d = gcd(A, B);
  auto ans = factorize(d).size() + 1;
  cout << ans << endl;
}
Problem p02900 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, g;
  cin >> a >> b;
  g = __gcd(a, b);
  set<int> s;
  if (g % 2 == 0) {
    s.insert(2);
    while (g % 2 == 0)
      g /= 2;
  }
  for (int i = 3; i * i <= g; i += 2)
    if (g % i == 0) {
      s.insert(i);
      while (g % i == 0)
        g /= i;
    }
  if (g > 2)
    s.insert(g);
  cout << s.size() + 1 << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, g;
  cin >> a >> b;
  g = __gcd(a, b);
  set<int> s;
  if (g % 2 == 0) {
    s.insert(2);
    while (g % 2 == 0)
      g /= 2;
  }
  for (long long i = 3; i * i <= g; i += 2)
    if (g % i == 0) {
      s.insert(i);
      while (g % i == 0)
        g /= i;
    }
  if (g > 2)
    s.insert(g);
  cout << s.size() + 1 << endl;
}