Problem p02900 (C++)

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

/********************************************
This code belongs to Pranay Mishra
The following template belongs to Anil Kumar
*******************************************/

#define bolt                                                                   \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl "\n"
typedef long long ll;
typedef long double ld;
const int mod = 1000000007;
bool isPrime(ll n) {
  if (n == 0 || n == 1)
    return false;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
ll factorial(ll n) { return (n == 1 || n == 0) ? 1 : n * factorial(n - 1); }
ll power(ll x, ll y) {
  ll res = 1;
  x = x % mod;
  while (y > 0) {
    if (y & 1)
      res = ((res % mod) * (x % mod)) % mod;
    y = y >> 1;
    x = ((x % mod) * (x % mod)) % mod;
  }
  return res;
}
ll ncr(ll n, ll r) {
  ll res = 1;
  if (r > n)
    return 0;
  if (r > n - r)
    r = n - r;
  for (ll i = 0; i < r; i++) {
    res = ((res % mod) * ((n - i) % mod)) % mod;
    res = ((res % mod) * (power(i + 1, mod - 2)) % mod) % mod;
  }
  return res;
}
ll gcd(ll a, ll b) {
  if (a == 0)
    return b;
  return gcd(b % a, a);
}
ll lcm(ll a, ll b) { return (a / gcd(a, b) * b); }
ll max(ll a, ll b) {
  ll ans = a > b ? a : b;
  return ans;
}
ll min(ll a, ll b) {
  ll ans = a < b ? a : b;
  return ans;
}
/***********************************************************************/
/***********************************************************************/
int main() {
  bolt;
  ll a, b;
  cin >> a >> b;
  ll k = gcd(a, b);
  ll i = 2;
  vector<long long int> st;
  if (k % 2 == 0) {
    st.push_back(2);
    while (k % 2 == 0) {
      k /= 2;
    }
  }
  for (int i = 3; i * i <= k; i += 2) {
    if (k % i == 0) {
      st.push_back(i);
      while (k > 1 && k % i == 0) {
        k /= i;
      }
    }
  }
  if (k > 1) {
    st.push_back(k);
  }
  k = st.size() + 1;
  cout << k;
}


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

/********************************************
This code belongs to Pranay Mishra
The following template belongs to Anil Kumar
*******************************************/

#define bolt                                                                   \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl "\n"
typedef long long ll;
typedef long double ld;
const int mod = 1000000007;
bool isPrime(ll n) {
  if (n == 0 || n == 1)
    return false;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
ll factorial(ll n) { return (n == 1 || n == 0) ? 1 : n * factorial(n - 1); }
ll power(ll x, ll y) {
  ll res = 1;
  x = x % mod;
  while (y > 0) {
    if (y & 1)
      res = ((res % mod) * (x % mod)) % mod;
    y = y >> 1;
    x = ((x % mod) * (x % mod)) % mod;
  }
  return res;
}
ll ncr(ll n, ll r) {
  ll res = 1;
  if (r > n)
    return 0;
  if (r > n - r)
    r = n - r;
  for (ll i = 0; i < r; i++) {
    res = ((res % mod) * ((n - i) % mod)) % mod;
    res = ((res % mod) * (power(i + 1, mod - 2)) % mod) % mod;
  }
  return res;
}
ll gcd(ll a, ll b) {
  if (a == 0)
    return b;
  return gcd(b % a, a);
}
ll lcm(ll a, ll b) { return (a / gcd(a, b) * b); }
ll max(ll a, ll b) {
  ll ans = a > b ? a : b;
  return ans;
}
ll min(ll a, ll b) {
  ll ans = a < b ? a : b;
  return ans;
}
/***********************************************************************/
/***********************************************************************/
int main() {
  bolt;
  ll a, b;
  cin >> a >> b;
  ll k = gcd(a, b);
  ll i = 2;
  vector<long long int> st;
  if (k % 2 == 0) {
    st.push_back(2);
    while (k % 2 == 0) {
      k /= 2;
    }
  }
  for (ll i = 3; i * i <= k; i += 2) {
    if (k % i == 0) {
      st.push_back(i);
      while (k > 1 && k % i == 0) {
        k /= i;
      }
    }
  }
  if (k > 1) {
    st.push_back(k);
  }
  k = st.size() + 1;
  cout << k;
}