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

Buggy submission (status: Runtime Error):
// Warmdust Code
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define db double
#define ll long long
#define ull unsigned long long
#define ft float
#define PI acos(-1)
#define L(i, a, b) for (int i = a; i <= b; i++)
#define R(i, a, b) for (int i = a; i >= b; i--)
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
#define Warmdust int main() {
#define RETURN                                                                 \
  return 0;                                                                    \
  }
#define TvT ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
using namespace std;
const int maxn = 1e5 + 7;
const int mod = 10000 + 7;
int sz[maxn];
// vector<ll>v;
Warmdust TvT;
ll a, b;
int cnt = 0;
cin >> a >> b;
ll s = __gcd(a, b);
//	cout << s << endl;
for (ll i = 1; i * i <= s; i++) {
  if (s % i == 0) {
    sz[cnt++] = i;
    if (i * i == s)
      continue;
    sz[cnt++] = s / i;
  }
}
sort(sz, sz + cnt);
R(i, cnt - 1, 1) {
  //		int sum = cnt;
  R(j, i - 1, 1) {
    if (sz[i] % sz[j] == 0) {
      cnt--;
      break;
    }
  }
  // mn=min(mn,sum) ;
}
cout << cnt << endl;
RETURN


Fixed submission:
// Warmdust Code
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define db double
#define ll long long
#define ull unsigned long long
#define ft float
#define PI acos(-1)
#define L(i, a, b) for (int i = a; i <= b; i++)
#define R(i, a, b) for (int i = a; i >= b; i--)
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
#define Warmdust int main() {
#define RETURN                                                                 \
  return 0;                                                                    \
  }
#define TvT ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
using namespace std;
const int maxn = 1e5 + 7;
const int mod = 10000 + 7;
ll sz[maxn];
// vector<ll>v;
Warmdust TvT;
ll a, b;
int cnt = 0;
cin >> a >> b;
ll s = __gcd(a, b);
//	cout << s << endl;
for (ll i = 1; i * i <= s; i++) {
  if (s % i == 0) {
    sz[cnt++] = i;
    if (i * i == s)
      continue;
    sz[cnt++] = s / i;
  }
}
sort(sz, sz + cnt);
R(i, cnt - 1, 1) {
  //		int sum = cnt;
  R(j, i - 1, 1) {
    if (sz[i] % sz[j] == 0) {
      cnt--;
      break;
    }
  }
  // mn=min(mn,sum) ;
}
cout << cnt << endl;
RETURN
Problem p02900 (C++)

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

int main() {
  long long A, B, ans = 1;
  cin >> A >> B;
  long long g = __gcd(A, B);
  vector<long long> K;
  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;

int main() {
  long long A, B, ans = 1;
  cin >> A >> B;
  long long g = __gcd(A, B);
  for (long long 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 <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

long int gcd(long int x, long int y) { return y ? gcd(y, x % y) : x; }

vector<pair<long int, int>> factorize(long int N) {
  vector<pair<long int, int>> res;
  for (long int i = 2; i + i <= N; ++i) {
    if (N % i)
      continue;
    res.emplace_back(i, 0);
    while (N % i == 0) {
      N /= i;
      res.back().second++;
    }
  }
  if (N != 1)
    res.emplace_back(N, 1);
  return res;
}

int main() {

  long int a, b;
  cin >> a >> b;
  long int g = gcd(a, b);
  auto f = factorize(g);
  int ans = f.size() + 1;
  cout << ans << endl;

  return 0;
}

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

long int gcd(long int x, long int y) { return y ? gcd(y, x % y) : x; }

vector<pair<long int, int>> factorize(long int N) {
  vector<pair<long int, int>> res;
  for (long int i = 2; i * i <= N; ++i) {
    if (N % i)
      continue;
    res.emplace_back(i, 0);
    while (N % i == 0) {
      N /= i;
      res.back().second++;
    }
  }
  if (N != 1)
    res.emplace_back(N, 1);
  return res;
}

int main() {

  long int a, b;
  cin >> a >> b;
  long int g = gcd(a, b);
  auto f = factorize(g);
  int ans = f.size() + 1;
  cout << ans << endl;

  return 0;
}
Problem p02900 (C++)

Buggy submission (status: Time Limit Exceeded):
/* C++14(GCC5.4.1) */
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
static const ll MAX_N = 1000000;

// m>=nを想定している
ll gcd(ll m, ll n) {
  if (n == 0)
    return m;
  return gcd(n, m % n);
}

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

// [[vectorを使うかmapを使うか.]]
// 要素の個数に興味があるので
// insertがO(1)のvectorの方が
// insertにO(log n)かかるmapよりも
// 使えるってことね!

// 素因数分解
// nを次々と割っていく
// i=2からスタート
vector<pair<ll, int>> prime_factor(ll n) {
  vector<pair<ll, int>> res;
  for (int i = 2; i * i <= n; ++i) {
    int k = 0;
    while (n % i == 0) {
      n /= i;
      k++;
    }
    // iで一回以上割り切れるなら追加
    if (k != 0)
      res.push_back({i, k});
  }
  // 残ったnが1ではない時、i*i<=nに引っかかったn=iである.
  if (n != 1)
    res.push_back({n, 1});
  return res;
}

int main(void) {
  // 入力
  ll a, b;
  cin >> a >> b;

  // a,bのGCDを求める
  ll gcd_of_ab;
  if (a >= b)
    gcd_of_ab = gcd(a, b);
  else
    gcd_of_ab = gcd(b, a);

  // 求めたいのはGCD以下のGCDを割り切る素数の個数
  ll ans = 1;
  auto m = prime_factor(gcd_of_ab);
  ans += m.size();

  cout << ans;
  return 0;
}

Fixed submission:
/* C++14(GCC5.4.1) */
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
static const ll MAX_N = 1000000;

// m>=nを想定している
ll gcd(ll m, ll n) {
  if (n == 0)
    return m;
  return gcd(n, m % n);
}

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

// [[vectorを使うかmapを使うか.]]
// 要素の個数に興味があるので
// insertがO(1)のvectorの方が
// insertにO(log n)かかるmapよりも
// 使えるってことね!

// 素因数分解
// nを次々と割っていく
// i=2からスタート
vector<pair<ll, int>> prime_factor(ll n) {
  vector<pair<ll, int>> res;
  for (ll i = 2; i * i <= n; i++) {
    int k = 0;
    while (n % i == 0) {
      n /= i;
      k++;
    }
    // iで一回以上割り切れるなら追加
    if (k != 0)
      res.push_back({i, k});
  }
  // 残ったnが1ではない時、i*i<=nに引っかかったn=iである.
  if (n != 1)
    res.push_back({n, 1});
  return res;
}

int main(void) {
  // 入力
  ll a, b;
  cin >> a >> b;

  // a,bのGCDを求める
  ll gcd_of_ab;
  if (a >= b)
    gcd_of_ab = gcd(a, b);
  else
    gcd_of_ab = gcd(b, a);

  // 求めたいのはGCD以下のGCDを割り切る素数の個数
  ll ans = 1;
  auto m = prime_factor(gcd_of_ab);
  ans += m.size();

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


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

Buggy submission (status: Time Limit Exceeded):
/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ */
// codeforces
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define mp make_pair
#define pb push_back
#define sz(v) ((int)v.size())
#define all(v) v.begin(), v.end()
void parseArray(ll *A, ll n) {
  for (ll K = 0; K < n; K++) {
    cin >> A[K];
  }
}
ll modInverse(ll a, ll b) {
  return 1 < a ? b - modInverse(b % a, a) * b / a : 1;
}
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); }
ld dist(ll x, ll y, ll a, ll b) {
  return sqrt((x - a) * (x - a) + (y - b) * (y - b));
}
void debug(ll *a, ll n) {
  for (int k = 0; k < n; k++) {
    cout << a[k] << " ";
  }
  cerr << "\n";
}

int main() {
  ll a, b;
  cin >> a >> b;
  vector<ll> div;
  ll y = max(a, b);
  ll x = min(a, b);
  ll ans = 1;
  if (x % 2 == 0) {
    if (y % 2 == 0)
      ans++;
    x /= 2;
  }
  while (x % 2 == 0)
    x /= 2;

  for (int i = 3; i * i <= x; i += 2) {
    if (x % i == 0) {
      if (y % i == 0)
        ans++;
      x /= i;
    }
    while (x % i == 0)
      x /= i;
  }
  if (x > 2 && y % x == 0)
    ans++;

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

Fixed submission:
/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ */
// codeforces
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define mp make_pair
#define pb push_back
#define sz(v) ((int)v.size())
#define all(v) v.begin(), v.end()
void parseArray(ll *A, ll n) {
  for (ll K = 0; K < n; K++) {
    cin >> A[K];
  }
}
ll modInverse(ll a, ll b) {
  return 1 < a ? b - modInverse(b % a, a) * b / a : 1;
}
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); }
ld dist(ll x, ll y, ll a, ll b) {
  return sqrt((x - a) * (x - a) + (y - b) * (y - b));
}
void debug(ll *a, ll n) {
  for (int k = 0; k < n; k++) {
    cout << a[k] << " ";
  }
  cerr << "\n";
}

int main() {
  ll a, b;
  cin >> a >> b;
  vector<ll> div;
  ll y = max(a, b);
  ll x = min(a, b);
  ll ans = 1;
  if (x % 2 == 0) {
    if (y % 2 == 0)
      ans++;
    x /= 2;
  }
  while (x % 2 == 0)
    x /= 2;

  for (ll i = 3; i * i <= x; i += 2) {
    if (x % i == 0) {
      if (y % i == 0)
        ans++;
      x /= i;
    }
    while (x % i == 0)
      x /= i;
  }
  if (x > 2 && y % x == 0)
    ans++;

  cout << ans << endl;
  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 g = __gcd(a, b);
  ll ans = 0;
  ll x = g;

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

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// typedef tree<int, nuint_type, less<int>, rb_tree_tag,
// tree_order_statistics_node_update> new_data_set;
#define int long long
#define MOD 1000000007
#define what_is(x) cerr << #x << " is " << x << endl;
#define loop(i, a, n) for (int i = a; i < n; i++)
#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, szof(x))
#define sortall(x) sort(aint(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626

#define fastio()                                                               \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
typedef pair<int, int> pt;

// int arr[2][2]={{0,1},{1,0}};
signed main() {

  fastio();
// #define LOCAL_DEFINE
#ifdef LOCAL_DEFINE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  // https://zhuhan0.blogspot.com/2017/09/leetcode-425-word-squares.html
  // https://yzygitzh.github.io/algorithm/2018/11/09/leetcode-summary.html
  // https://beginnersbook.com/2015/03/why-dont-we-call-run-method-directly-why-call-start-method/
  // https://leetcode.com/problems/lfu-cache/
  // int n,k;
  // cin>>n>>k;
  // vector<int> arr(n);
  // 	for(int i=0;i<n;i++)
  // 	{
  // 		cin>>arr[i];
  // 	}
  // 	set<int> hash;
  // 	int ans=0;
  // 	bool flag=false;
  // 	for(int i=0;i<k;i++)
  // 	{
  // 		if(hash.lower_bound(arr[i])!=hash.end())
  // 		{
  // 			flag=true;
  // 		}
  // 		hash.insert(arr[i]);
  // 	}
  // 	if(flag)
  // 	{
  // 		ans++;
  // 	}
  // 	bool flag1=false;
  // 	for(int i=k;i<n;i++)
  // 	{
  // 		cout<<ans<<endl;
  // 		hash.erase(arr[i-k]);
  // 		if(hash.lower_bound(arr[i])!=hash.end())
  // 		{
  // 			ans++;
  // 		}else if(hash.lower_bound(arr[i-k])!=hash.begin())
  // 		{
  // 			ans++;
  // 		}else{
  // 			flag1=true;
  // 		}

  // 		hash.insert(arr[i]);
  // 	}
  // 	if(!flag || !flag1)
  // 		ans++;
  // 	cout<<ans;

  ll a, b;
  cin >> a >> b;
  ll g = __gcd(a, b);
  ll ans = 0;
  ll x = g;

  for (int i = 2; i * i <= x; i++) {
    if (g % i == 0) {
      ans++;
      while ((g % i) == 0) {
        g = (g / i);
      }
    }
  }
  if (g != 1)
    ans++;
  cout << ans + 1;
}
Problem p02900 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll gcd(ll x, ll y) {
  if (x < y)
    swap(x, y);
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

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


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll gcd(ll x, ll y) {
  if (x < y)
    swap(x, y);
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

int main() {
  ll a, b;
  cin >> a >> b;
  ll g = gcd(a, b);
  ll ans = 0;
  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 + 1 << endl;
  return (0);
}
Problem p02900 (C++)

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

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

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

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

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

long long A, B, num;

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

int main() {
  cin >> A >> B;
  long long gc = gcd(A, B);
  long long k = gc;

  num++;
  for (int i = 2; i * i <= gc; i++) {
    if (k % i == 0) {
      num++;
      while (k % i == 0) {
        k /= i;
      }
    }
  }

  if (k > 1) {
    num++;
  }
  cout << num << endl;
}


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

long long A, B, num;

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

int main() {
  cin >> A >> B;
  long long gc = gcd(A, B);
  long long k = gc;

  num++;
  for (long long i = 2; i * i <= gc; i++) {
    if (k % i == 0) {
      num++;
      while (k % i == 0) {
        k /= i;
      }
    }
  }

  if (k > 1) {
    num++;
  }
  cout << num << endl;
}
Problem p02900 (C++)

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

map<long long, long long> prime_map;

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

void prime_factor(int64_t bak) {
  for (int i = 2; i * i <= bak; ++i) {
    while (bak % i == 0) {
      ++prime_map[i];
      bak /= i;
    }
  }
  if (bak > 1) {
    ++prime_map[bak];
  }
}

void prime_list(int64_t n) {
  for (int64_t i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      ++prime_map[i];
      n = n / i;
    }
  }
  if (n != 1) {
    ++prime_map[n];
  }
}

int main() {
  long long A, B;
  cin >> A >> B;
  long long gcd = cal_gcd(A, B);
  prime_factor(gcd);
  // prime_list(gcd);

  cout << prime_map.size() + 1 << endl;
}


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

map<long long, long long> prime_map;

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

void prime_factor(int64_t bak) {
  for (int64_t i = 2; i * i <= bak; ++i) {
    while (bak % i == 0) {
      ++prime_map[i];
      bak /= i;
    }
  }
  if (bak > 1) {
    ++prime_map[bak];
  }
}

void prime_list(int64_t n) {
  for (int64_t i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      ++prime_map[i];
      n = n / i;
    }
  }
  if (n != 1) {
    ++prime_map[n];
  }
}

int main() {
  long long A, B;
  cin >> A >> B;
  long long gcd = cal_gcd(A, B);
  prime_factor(gcd);
  // prime_list(gcd);

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
long long m, n, g, cnt = 1;
long long gcd(int m, int n) {
  if (m % n == 0)
    return n;
  else
    return gcd(n, m % n);
}
int main() {
  cin >> m >> n;
  g = gcd(m, n);
  for (long long i = 2; i * i <= g; i++) {
    if (g % i == 0) {
      cnt++;
      while (g % i == 0)
        g = g / i;
    }
  }
  if (g > 1)
    cnt++;
  cout << cnt << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
long long m, n, g, cnt = 1;
long long gcd(long long m, long long n) {
  if (m % n == 0)
    return n;
  else
    return gcd(n, m % n);
}
int main() {
  cin >> m >> n;
  g = gcd(m, n);
  for (long long i = 2; i * i <= g; i++) {
    if (g % i == 0) {
      cnt++;
      while (g % i == 0)
        g = 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;
typedef long long ll;

int main() {
  ll a, b;
  cin >> a >> b;
  ll n = a, m = b;
  map<ll, ll> res;
  for (int i = 2; i * i <= min(n, m); i++) {
    while (min(n, m) % i == 0) {
      if (max(n, m) % i == 0) {
        res[i]++;
        n /= i;
        m /= i;
      } else {
        if (min(n, m) == n) {
          n /= i;
        } else {
          m /= i;
        }
      }
    }
  }
  if (min(n, m) != 1) {
    if (max(m, n) % min(n, m) == 0)
      res[min(n, m)] = 1;
  }

  cout << res.size() + 1 << endl;
}

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

int main() {
  ll a, b;
  cin >> a >> b;
  ll n = a, m = b;
  map<ll, ll> res;
  for (ll i = 2; i * i <= min(n, m); i++) {
    while (min(n, m) % i == 0) {
      if (max(n, m) % i == 0) {
        res[i]++;
        n /= i;
        m /= i;
      } else {
        if (min(n, m) == n) {
          n /= i;
        } else {
          m /= i;
        }
      }
    }
  }
  if (min(n, m) != 1) {
    if (max(m, n) % min(n, m) == 0)
      res[min(n, m)] = 1;
  }

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

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

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

  ll count = 1;
  for (int i = 2; D >= i * i; i++) {
    if (D % i == 0) {
      count++;
      while (D % i == 0) {
        D = D / i;
      }
    }
  }
  if (D != 1)
    count++;
  printf("%lld\n", count);
}

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

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

  ll count = 1;
  for (ll i = 2; D >= i * i; i++) {
    if (D % i == 0) {
      count++;
      while (D % i == 0) {
        D = D / i;
      }
    }
  }
  if (D != 1)
    count++;
  printf("%lld\n", count);
}
Problem p02900 (C++)

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;

#define mt make_tuple
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sqr(x) ((ll)(x) * (x))

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

  ll a, b;
  cin >> a >> b;

  ll nzd = __gcd(a, b);

  vi v;

  for (int i = 2; i * i <= nzd; ++i) {
    bool jelUsao = false;

    while (nzd % i == 0) {
      jelUsao = true;
      nzd /= i;
    }

    if (jelUsao)
      v.pb(i);
  }

  if (nzd > 1)
    v.pb(nzd);

  cout << 1LL + (ll)v.size() << '\n';

  return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;

#define mt make_tuple
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sqr(x) ((ll)(x) * (x))

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

  ll a, b;
  cin >> a >> b;

  ll nzd = __gcd(a, b);

  vi v;

  for (ll i = 2; i * i <= nzd; ++i) {
    bool jelUsao = false;

    while (nzd % i == 0) {
      jelUsao = true;
      nzd /= i;
    }

    if (jelUsao)
      v.pb(i);
  }

  if (nzd > 1)
    v.pb(nzd);

  cout << 1LL + (ll)v.size() << '\n';

  return 0;
}
Problem p02900 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for (ll i = 0; i < n; i++)

int main() {
  ll a, b;
  cin >> a >> b;

  vector<bool> sosu(1000005, true);
  sosu[0] = false;
  for (ll i = 2; i <= 1000000; i++) {
    if (!sosu[i])
      continue;
    for (ll j = i * 2; j <= 1000000; j += i) {
      sosu[j] = false;
    }
  }

  set<ll> st1, st2;
  for (ll i = 1; i <= sqrt(a); i++) {
    if (a % i == 0) {
      st1.insert(i);
      st1.insert(a / i);
    }
  }
  for (ll i = 1; i <= sqrt(b); i++) {
    if (b % i == 0) {
      st2.insert(i);
      st2.insert(b / i);
    }
  }

  ll ans = 0;
  set<ll> st3;
  for (auto &x : st1) {
    if (x > 1000000) {
      if (st2.find(x) != st2.end()) {
        bool f = true;
        for (auto &xx : st3) {
          if (xx == 1)
            continue;
          if (x % xx == 0) {
            f = false;
            break;
          }
        }
        if (f) {
          ans++;
        }
      }
    }
    if (sosu[x] && st2.find(x) != st2.end()) {
      ans++;
      st3.insert(x);
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for (ll i = 0; i < n; i++)

int main() {
  ll a, b;
  cin >> a >> b;

  vector<bool> sosu(1000005, true);
  sosu[0] = false;
  for (ll i = 2; i <= 1000000; i++) {
    if (!sosu[i])
      continue;
    for (ll j = i * 2; j <= 1000000; j += i) {
      sosu[j] = false;
    }
  }

  set<ll> st1, st2;
  for (ll i = 1; i <= sqrt(a); i++) {
    if (a % i == 0) {
      st1.insert(i);
      st1.insert(a / i);
    }
  }
  for (ll i = 1; i <= sqrt(b); i++) {
    if (b % i == 0) {
      st2.insert(i);
      st2.insert(b / i);
    }
  }

  ll ans = 0;
  set<ll> st3;
  for (auto &x : st1) {
    if (x > 1000000) {
      if (st2.find(x) != st2.end()) {
        bool f = true;
        for (auto &xx : st3) {
          if (xx == 1)
            continue;
          if (x % xx == 0) {
            f = false;
            break;
          }
        }
        if (f) {
          ans++;
        }
      }
    } else if (sosu[x] && st2.find(x) != st2.end()) {
      ans++;
      st3.insert(x);
    }
  }
  cout << ans << endl;
}
Problem p02900 (C++)

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

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


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

int main() {
  int64_t A, B, C, ans = 1;
  cin >> A >> B;
  while (B != 0) {
    A %= B;
    swap(A, B);
  }
  C = A;
  for (int64_t i = 2; i * i <= C; i++) {
    if (C % i == 0) {
      ans++;
      while (C % i == 0) {
        C /= i;
      }
    }
  }
  if (C > 1) {
    ans++;
  }
  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;
  cin >> a >> b;
  long long commonfactor = __gcd(a, b);
  long long n = commonfactor;
  long count = 0;
  for (int i = 2; i * i <= commonfactor; i++) {
    if (n % i != 0) {
      continue;
    }
    while (n % i == 0) {
      n /= i;
    }
    count++;
  }

  if (n != 1) {
    count++;
  }
  cout << count + 1 << endl;
}


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

int main() {
  long long a, b;
  cin >> a >> b;
  long long commonfactor = __gcd(a, b);
  long long n = commonfactor;
  long long count = 0;
  for (long long i = 2; i * i <= commonfactor; i++) {
    if (n % i != 0) {
      continue;
    }
    while (n % i == 0) {
      n /= i;
    }
    count++;
  }

  if (n != 1) {
    count++;
  }
  cout << count + 1 << endl;
}
Problem p02900 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>

using namespace std;

int u[111];

typedef long long ll;
const int maxn = (int)1e5 + 1;
const int inf = (int)1e9 + 7;

int a[maxn], b[111];

int cnt[maxn];

string s, t;

int ans = 0, sum1, sum2, sum3;

ll n, k;

int dp[maxn];

vector<ll> v, g;

int now = 0;

bool isprime(ll x) {
  for (ll i = 2; i <= sqrt(x); i++) {
    if (x % i == 0) {
      return 0;
    }
  }
  return 1;
}

ll GCD(ll u, ll v) {
  while (v != 0) {
    ll r = u % v;
    u = v;
    v = r;
  }
  return u;
}
int main() {
  cin >> n >> k;
  now = GCD(n, k);
  for (ll i = 1; i <= sqrt(now); i++) {
    if (now % i == 0) {
      v.push_back(i);
      v.push_back(now / i);
    }
  }
  if (ll(sqrt(now)) * ll(sqrt(now)) == now)
    v.pop_back();
  sort(v.begin(), v.end());
  for (ll i : v)
    if (isprime(i)) {
      ans++;
    }
  cout << ans;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>

using namespace std;

int u[111];

typedef long long ll;
const int maxn = (int)1e5 + 1;
const int inf = (int)1e9 + 7;

int a[maxn], b[111];

int cnt[maxn];

string s, t;

int ans = 0, sum1, sum2, sum3;

ll n, k;

int dp[maxn];

vector<ll> v, g;

ll now = 0;

bool isprime(ll x) {
  for (ll i = 2; i <= sqrt(x); i++) {
    if (x % i == 0) {
      return 0;
    }
  }
  return 1;
}

ll GCD(ll u, ll v) {
  while (v != 0) {
    ll r = u % v;
    u = v;
    v = r;
  }
  return u;
}
int main() {
  cin >> n >> k;
  now = GCD(n, k);
  for (ll i = 1; i <= sqrt(now); i++) {
    if (now % i == 0) {
      v.push_back(i);
      v.push_back(now / i);
    }
  }
  if (ll(sqrt(now)) * ll(sqrt(now)) == now)
    v.pop_back();
  sort(v.begin(), v.end());
  for (ll i : v)
    if (isprime(i)) {
      ans++;
    }
  cout << ans;
}
Problem p02900 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll n, m;
  cin >> n >> m;
  int ans = 0;
  ll x = __gcd(n, m);
  for (ll i = 2; i <= x; i++) {
    if (x % i == 0) {
      ans++;
      while (x % i == 0) {
        x /= i;
      }
    }
  }
  if (x > 1)
    ans += 2;
  else
    ans++;
  cout << ans << endl;
  return 0;
}

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

Buggy submission (status: Time Limit Exceeded):
#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, S;
  int count;
  count = 1;
  cin >> A >> B;

  if (A > B) {
    S = gcd(A, B);
  } else {
    S = gcd(B, A);
  }

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


Fixed submission:
#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, S;
  int count;
  count = 1;
  cin >> A >> B;

  if (A > B) {
    S = gcd(A, B);
  } else {
    S = gcd(B, A);
  }

  for (long long i = 2; i * i <= S; i++) {
    if (S % i == 0) {
      count++;
      while (S % i == 0)
        S /= i;
    }
  }
  if (S != 1)
    count++;
  cout << count << endl;
}
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) {
  if (a % b == 0) {
    return b;
  } else {
    return gcd(b, a % b);
  }
}

int main() {
  int64_t A, B, gc;
  int64_t cnt = 1;
  cin >> A >> B;
  if (A >= B)
    gc = gcd(A, B);
  else if (A < B)
    gc = gcd(B, A);
  int64_t tmp = gc;
  for (int i = 2; i * i < gc; i++) {

    if (tmp % i == 0) {
      cnt++;
      while (tmp % i == 0) {
        tmp /= i;
      }
    }
  }
  if (tmp != 1)
    cnt++;

  cout << cnt << endl;
}


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

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

int main() {
  int64_t A, B, gc;
  int64_t cnt = 1;
  cin >> A >> B;
  if (A >= B)
    gc = gcd(A, B);
  else if (A < B)
    gc = gcd(B, A);
  int64_t tmp = gc;
  for (int64_t i = 2; i * i < tmp; i++) {

    if (tmp % i == 0) {
      cnt++;
      while (tmp % i == 0) {
        tmp /= i;
      }
    }
  }
  if (tmp != 1)
    cnt++;

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, n) for (int i = n - 1; i >= 0; --i)
#define yesno(flg)                                                             \
  if (flg) {                                                                   \
    cout << "YES" << endl;                                                     \
  } else {                                                                     \
    cout << "NO" << endl;                                                      \
  }
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P1;
typedef pair<int, int> Pi;
typedef pair<double, Pi> Pdi;
typedef pair<ll, int> Pli;
typedef pair<P1, ll> P2;
const ll INF = 100000007;
struct edge {
  int to, cost;
};
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
struct Road {
  double cost;
  int a, b;
};

ll gcd(ll a2, ll b2) {
  ll t;
  if (a2 < b2) {
    t = a2;
    a2 = b2;
    b2 = t;
  }
  while (b2 != 0) {
    t = a2 % b2;
    a2 = b2;
    b2 = t;
  }
  return a2;
}

int main() {

  ll a, b;
  cin >> a >> b;

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

  cout << total << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, n) for (int i = n - 1; i >= 0; --i)
#define yesno(flg)                                                             \
  if (flg) {                                                                   \
    cout << "YES" << endl;                                                     \
  } else {                                                                     \
    cout << "NO" << endl;                                                      \
  }
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P1;
typedef pair<int, int> Pi;
typedef pair<double, Pi> Pdi;
typedef pair<ll, int> Pli;
typedef pair<P1, ll> P2;
const ll INF = 100000007;
struct edge {
  int to, cost;
};
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
struct Road {
  double cost;
  int a, b;
};

ll gcd(ll a2, ll b2) {
  ll t;
  if (a2 < b2) {
    t = a2;
    a2 = b2;
    b2 = t;
  }
  while (b2 != 0) {
    t = a2 % b2;
    a2 = b2;
    b2 = t;
  }
  return a2;
}

int main() {

  ll a, b;
  cin >> a >> b;

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

  cout << total << endl;

  return 0;
}
Problem p02900 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <utility>
#include <vector>

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

vector<pair<ll, int>> factorize(ll n) {
  vector<pair<ll, int>> res;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i)
      continue;
    res.emplace_back(i, 0);
    while (n % i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if (n != 1)
    res.emplace_back(n, 1);
  return res;
}

int main() {
  int a, b;
  cin >> a >> b;
  ll m = gcd(a, b);

  auto vp = factorize(m);
  cout << vp.size() + 1 << endl;
}


Fixed submission:
#include <iostream>
#include <utility>
#include <vector>

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

vector<pair<ll, int>> factorize(ll n) {
  vector<pair<ll, int>> res;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i)
      continue;
    res.emplace_back(i, 0);
    while (n % i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if (n != 1)
    res.emplace_back(n, 1);
  return res;
}

int main() {
  ll a, b;
  cin >> a >> b;
  ll m = gcd(a, b);

  auto vp = factorize(m);
  cout << vp.size() + 1 << endl;
}
Problem p02900 (C++)

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

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl

using namespace std;
using i64 = long long;

// m > n >= 0
template <class T> T gcd(T m, T n) {
  if (n == 0)
    return m;
  return gcd(n, m % n);
}

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

  // GCD(A,B) を割り切れる素数の個数 +1
  if (A < B)
    swap(A, B);
  i64 g; // GCD
  g = gcd(A, B);

  int gsq = sqrt(g);
  vector<int> primelist{2};
  vector<bool> seen(gsq + 10, false);
  // エラトステネスの篩
  // gsq以上の素数は高々一つ
  // なのでgsq以下の素数で順々に割っていけばよい
  for (int num = 3; num <= gsq; num++) {
    if (seen[num])
      continue;
    bool isprime = true;
    for (auto &&p : primelist) {
      if (num % p == 0) {
        isprime = false;
        break;
      }
    }
    if (isprime)
      primelist.push_back(num);
  }

  int counter = 1;
  for (auto &&p : primelist) {
    if (g % p != 0)
      continue;
    counter++;
    while (g % p == 0) {
      g /= p;
    }
  }
  if (g != 1)
    counter++;

  /*
  debug(g);
  for (auto &&p : primelist)
  {
      debug(p);
  }
  */

  cout << counter << endl;

  return 0;
}

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

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl

using namespace std;
using i64 = long long;

// m > n >= 0
template <class T> T gcd(T m, T n) {
  if (n == 0)
    return m;
  return gcd(n, m % n);
}

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

  // GCD(A,B) を割り切れる素数の個数 +1
  if (A < B)
    swap(A, B);
  i64 g; // GCD
  g = gcd(A, B);

  int gsq = sqrt(g);
  vector<int> primelist{2};
  vector<bool> seen(gsq + 10, false);
  // エラトステネスの篩
  // gsq以上の素数は高々一つ
  // なのでgsq以下の素数で順々に割っていけばよい
  for (int num = 3; num <= gsq; num++) {
    if (seen[num])
      continue;
    for (int i = 2; i * num <= gsq; i++)
      seen[i * num] = true;
    primelist.push_back(num);
  }

  int counter = 1;
  for (auto &&p : primelist) {
    if (g % p != 0)
      continue;
    counter++;
    while (g % p == 0) {
      g /= p;
    }
  }
  if (g != 1)
    counter++;

  /*
  debug(g);
  for (auto &&p : primelist)
  {
      debug(p);
  }
  */

  cout << counter << endl;

  return 0;
}
Problem p02900 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
#define debug(x) cerr << #x << ' ' << x << endl;
using namespace std;

typedef long long ll;
const int mod = 1e9 + 7;
const int MAXN = 2e5 + 7;

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

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
#define debug(x) cerr << #x << ' ' << x << endl;
using namespace std;

typedef long long ll;
const int mod = 1e9 + 7;
const int MAXN = 2e5 + 7;

int main(int argc, char const *argv[]) {
  ll a, b;
  cin >> a >> b;
  ll g = __gcd(a, b);
  int ans = 1;
  for (ll i = 2; i * i <= g; ++i) {
    if (g % i != 0)
      continue;
    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 <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for (int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

ll prime_factor_num(ll n) {
  ll ret = 0;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      ret += 1;
      while (n % i == 0)
        n /= i;
    }
  }
  if (n != 1)
    ret += 1;
  return ret;
}

int main() {
  ll A, B;
  cin >> A >> B;
  ll g = __gcd(A, B);
  cout << prime_factor_num(g) + 1 << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for (int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

ll prime_factor_num(ll n) {
  ll ret = 0;
  for (int i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) {
      ret += 1;
      while (n % i == 0)
        n /= i;
    }
  }
  if (n != 1)
    ret += 1;
  return ret;
}

int main() {
  ll A, B;
  cin >> A >> B;
  ll g = __gcd(A, B);
  cout << prime_factor_num(g) + 1 << endl;
  return 0;
}
Problem p02900 (C++)

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

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

int main() {
  ll a, b;
  cin >> a >> b;
  ll g = __gcd(a, b);
  if (g == 1) {
    cout << 1 << endl;
    return 0;
  }
  cout << prime_factor(g).size() + 1 << endl;
}


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

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i];
      n /= i;
    }
  }
  if (n != 1)
    res[n] = 1;
  return res;
}

int main() {
  ll a, b;
  cin >> a >> b;
  ll g = __gcd(a, b);
  if (g == 1) {
    cout << 1 << endl;
    return 0;
  }
  cout << prime_factor(g).size() + 1 << endl;
}
Problem p02900 (C++)

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

bool is_prime(long long _Num) {
  if (_Num < 2)
    return false;
  if (_Num % 2 == 0) {
    if (_Num == 2)
      return true;
    else
      return false;
  }
  bool prime = true;
  for (long long i = 3; i <= sqrt(_Num); i += 2) {
    if (_Num % i == 0) {
      prime = false;
      break;
    }
  }
  return prime;
}

int main() {
  long long A, B;
  cin >> A >> B;
  if (A < B)
    swap(A, B); // A >= B

  set<long long> ans;
  ans.insert(1);
  for (long long i = 2; i <= sqrt(A); i++) {
    long long j = B / i;
    long long k = A / i;
    if (A % i == 0 && B % i == 0 && is_prime(i))
      ans.insert(i);
    if (A % j == 0 && B % j == 0 && is_prime(j))
      ans.insert(j);
    if (A % k == 0 && B % k == 0 && is_prime(k))
      ans.insert(k);
  }
  if (A == B && is_prime(A))
    ans.insert(A);

  cout << ans.size() << endl;
  return 0;
}

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

bool is_prime(long long _Num) {
  if (_Num < 2)
    return false;
  if (_Num % 2 == 0) {
    if (_Num == 2)
      return true;
    else
      return false;
  }
  bool prime = true;
  for (long long i = 3; i <= sqrt(_Num); i += 2) {
    if (_Num % i == 0) {
      prime = false;
      break;
    }
  }
  return prime;
}

int main() {
  long long A, B;
  cin >> A >> B;
  if (A < B)
    swap(A, B); // A >= B

  set<long long> ans;
  ans.insert(1);
  for (long long i = 2; i <= sqrt(A); i++) {
    if (A % i == 0) {
      long long j = A / i;
      if (B % i == 0 && is_prime(i))
        ans.insert(i);
      if (B % j == 0 && is_prime(j))
        ans.insert(j);
    }
    if (B % i == 0) {
      long long j = B / i;
      if (A % i == 0 && is_prime(i))
        ans.insert(i);
      if (A % j == 0 && is_prime(j))
        ans.insert(j);
    }
  }
  if (A == B && is_prime(A))
    ans.insert(A);

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

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

using namespace std;
typedef long long ll;

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

vector<pair<ll, int>> factorize(ll n) {
  vector<pair<ll, int>> res;
  for (ll i = 0; i * i <= n; ++i) {
    if (n % i)
      continue;
    res.emplace_back(i, 0);
    while (n % i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if (n != 1)
    res.emplace_back(n, 1);
  return res;
}

int main() {
  ll a, b;
  cin >> a >> b;
  ll gcdv = gcd(a, b);
  auto f = factorize(gcdv);
  cout << f.size() + 1;
  return 0;
}


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

using namespace std;
typedef long long ll;

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

vector<pair<ll, int>> factorize(ll n) {
  vector<pair<ll, int>> res;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i)
      continue;
    res.emplace_back(i, 0);
    while (n % i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if (n != 1)
    res.emplace_back(n, 1);
  return res;
}

int main() {
  ll a, b;
  cin >> a >> b;
  ll gcdv = gcd(a, b);
  auto f = factorize(gcdv);
  cout << f.size() + 1;
  return 0;
}