Problem p02900 (C++)

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define reps(i, n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i, n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i, n) for (int i = (int)(n); i > 0; --i)
#define loop(i, x, n) for (int i = (int)(x); i < (n); ++i)
#define loops(i, x, n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i, x, n) for (int i = (int)(x); i > (n); --i)
#define loopds(i, x, n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i, s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i, s) for (auto i = --end(s); i != begin(s); --i)
#define all(f, x, ...)                                                         \
  [&](decltype(x) &whole) {                                                    \
    return (f)(begin(whole), end(whole), ##__VA_ARGS__);                       \
  }(x)
#define rall(f, x, ...)                                                        \
  [&](decltype(x) &whole) {                                                    \
    return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__);                     \
  }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
constexpr ll mod = static_cast<ll>(1e9 + 7);
std::ostream &endn(std::ostream &os) { return os.put(os.widen('\n')); }
template <class T> constexpr int sz(const T &a) { return (int)a.size(); }
template <class T, class... Args> constexpr void mins(T &a, Args... args) {
  a = min<T>({a, args...});
}
template <class T, class... Args> constexpr void maxs(T &a, Args... args) {
  a = max<T>({a, args...});
}

template <class T> constexpr T gcd(T a, T b) {
  if (a < b)
    gcd(b, a);
  T r = 0;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}
template <class T> constexpr T lcm(T a, T b) {
  T g = gcd<T>(a, b);
  return a / g * b;
}

ll a, b;
void solve() {
  cin >> a >> b;

  auto l = gcd(a, b);
  ll ans = 0;
  int e = (int)ceil(sqrt(l));
  vector<int> vec;
  reps(i, e) {
    if (l == 0)
      break;
    if (l % i == 0) {
      if (l / i != 1)
        vec.push_back(l / i);
      if (i != 1) {
        while (l % i == 0)
          l /= i;
      }
      ++ans;
    }
  }
  all(sort, vec);
  rep(i, vec.size()) {
    if (l == 0)
      break;
    if (l % vec[i] == 0) {
      if (i != 1) {
        while (l % vec[i] == 0)
          l /= vec[i];
      }
      ++ans;
    }
  }
  cout << ans << endn;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  solve();
  cout << flush;
  return 0;
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define reps(i, n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i, n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i, n) for (int i = (int)(n); i > 0; --i)
#define loop(i, x, n) for (int i = (int)(x); i < (n); ++i)
#define loops(i, x, n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i, x, n) for (int i = (int)(x); i > (n); --i)
#define loopds(i, x, n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i, s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i, s) for (auto i = --end(s); i != begin(s); --i)
#define all(f, x, ...)                                                         \
  [&](decltype(x) &whole) {                                                    \
    return (f)(begin(whole), end(whole), ##__VA_ARGS__);                       \
  }(x)
#define rall(f, x, ...)                                                        \
  [&](decltype(x) &whole) {                                                    \
    return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__);                     \
  }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
constexpr ll mod = static_cast<ll>(1e9 + 7);
std::ostream &endn(std::ostream &os) { return os.put(os.widen('\n')); }
template <class T> constexpr int sz(const T &a) { return (int)a.size(); }
template <class T, class... Args> constexpr void mins(T &a, Args... args) {
  a = min<T>({a, args...});
}
template <class T, class... Args> constexpr void maxs(T &a, Args... args) {
  a = max<T>({a, args...});
}

template <class T> constexpr T gcd(T a, T b) {
  if (a < b)
    gcd(b, a);
  T r = 0;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}
template <class T> constexpr T lcm(T a, T b) {
  T g = gcd<T>(a, b);
  return a / g * b;
}

ll a, b;
void solve() {
  cin >> a >> b;

  auto l = gcd(a, b);
  ll ans = 0;
  int e = (int)ceil(sqrt(l));
  vector<ll> vec;
  reps(i, e) {
    if (l == 0)
      break;
    if (l % i == 0) {
      if (l / i != 1)
        vec.push_back(l / i);
      if (i != 1) {
        while (l % i == 0)
          l /= i;
      }
      ++ans;
    }
  }
  all(sort, vec);
  rep(i, vec.size()) {
    if (l == 0)
      break;
    if (l % vec[i] == 0) {
      if (i != 1) {
        while (l % vec[i] == 0)
          l /= vec[i];
      }
      ++ans;
    }
  }
  cout << ans << endn;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  solve();
  cout << flush;
  return 0;
}