Problem p02900 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define popb pop_back()
#define sz size()
#define int long long
#define y1 dfsdsfsdfsd
#define next fdsfsdfjkl
#define endl "\n"
#define speed                                                                  \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
double pi = acos(-1.0);
int mod = 1e9 + 7;
const double eps = (double)1e-9;
const ll INF = 1e18 + 7;
/////////////////////////////////////////

int a, b;
vector<int> find_dividers(int x) {
  vector<int> dividers;

  for (int i = 1; i <= sqrt(x); i++) {
    if (x % i == 0) {
      dividers.push_back(i);

      // для корня из x не существует парного делителя
      if (i * i != x) {
        dividers.push_back(x / i);
      }
    }
  }

  return dividers;
}

bool is_prime(int x) {
  for (int i = 2; i <= sqrt(x); i++) {
    if (x % i == 0) {
      return false;
    }
  }

  return true;
}
int used[20000100];
signed main() {
  speed;
  cin >> a >> b;

  vector<int> A = find_dividers(a);
  vector<int> B = find_dividers(b);

  int cnt = 0;

  for (int i = 0; i < A.size(); i++) {
    if (is_prime(A[i]) && used[A[i]] == 0 && a % A[i] == 0 && b % A[i] == 0) {
      used[A[i]] = 1;
      cnt++;
      // cout<<A[i]<<" ";
    }
  }

  for (int i = 0; i < B.size(); i++) {
    if (is_prime(B[i]) && used[B[i]] == 0 && b % B[i] == 0 && a % B[i] == 0) {
      used[B[i]] = 1;
      cnt++;
      // cout<<B[i]<<" ";
    }
  }

  cout << cnt << endl;
}


Fixed submission:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define popb pop_back()
#define sz size()
#define int long long
#define y1 dfsdsfsdfsd
#define next fdsfsdfjkl
#define endl "\n"
#define speed                                                                  \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
double pi = acos(-1.0);
int mod = 1e9 + 7;
const double eps = (double)1e-9;
const ll INF = 1e18 + 7;
/////////////////////////////////////////

int a, b;
vector<int> find_dividers(int x) {
  vector<int> dividers;

  for (int i = 1; i <= sqrt(x); i++) {
    if (x % i == 0) {
      dividers.push_back(i);

      // для корня из x не существует парного делителя
      if (i * i != x) {
        dividers.push_back(x / i);
      }
    }
  }

  return dividers;
}

bool is_prime(int x) {
  for (int i = 2; i <= sqrt(x); i++) {
    if (x % i == 0) {
      return false;
    }
  }

  return true;
}
map<int, int> used;
signed main() {
  speed;
  cin >> a >> b;

  vector<int> A = find_dividers(a);
  vector<int> B = find_dividers(b);

  int cnt = 0;

  for (int i = 0; i < A.size(); i++) {
    if (is_prime(A[i]) && used[A[i]] == 0 && a % A[i] == 0 && b % A[i] == 0) {
      used[A[i]] = 1;
      cnt++;
      // cout<<A[i]<<" ";
    }
  }

  for (int i = 0; i < B.size(); i++) {
    if (is_prime(B[i]) && used[B[i]] == 0 && b % B[i] == 0 && a % B[i] == 0) {
      used[B[i]] = 1;
      cnt++;
      // cout<<B[i]<<" ";
    }
  }

  cout << cnt << endl;
}