Problem p02900 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int divisorList[1000001] = {0};

// WA おそらく1000000を超える素数が答えにあるが出力していない
int main(void) {
  unsigned long long A, B;
  cin >> A >> B;
  vector<int> divisor;
  vector<unsigned long long> AHighDiv, BHighDiv;
  for (int i = 1; i <= 1000000; i++) {
    if ((A % i == 0) && (B % i == 0))
      divisor.push_back(i);
    if (A % i == 0) {
      if ((A / i) > 1000000)
        AHighDiv.push_back(A / i);
    }
    if (B % i == 0) {
      if ((B / i) > 1000000)
        BHighDiv.push_back(B / i);
    }
  }

  // 素数リストを作る
  for (int i = 2; i <= 1000000; i++) {
    if (divisorList[i] == 0) {
      for (int j = i * 2; j <= 1000000; j += i) {
        divisorList[j]++;
      }
    }
  }

  int ans = 0;
  for (unsigned int i = 0; i < divisor.size(); i++) {
    if (divisorList[divisor[i]] == 0)
      ans++;
  }
  if ((AHighDiv.size() > 0) && (BHighDiv.size() > 0)) {
    sort(AHighDiv.begin(), AHighDiv.end());
    sort(BHighDiv.begin(), BHighDiv.end());
    int Apos = 0, Bpos = 0;
    while (Apos < AHighDiv.size() && Bpos < BHighDiv.size()) {
      if (AHighDiv[Apos] == BHighDiv[Bpos]) {
        // 素数か確認する
        bool primeNumber = true;
        for (unsigned int i = 2; i < 1000000; i++) {
          if (divisorList[i] == 0) {
            if ((AHighDiv[Apos] % divisorList[i]) == 0) {
              primeNumber = false;
              break;
            }
          }
        }
        if (primeNumber)
          ans++;
        Apos++, Bpos++;
      } else if (AHighDiv[Apos] > BHighDiv[Bpos]) {
        Bpos++;
      } else if (AHighDiv[Apos] < BHighDiv[Bpos]) {
        Apos++;
      }
    }
  }

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


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

int divisorList[1000001] = {0};

// WA おそらく1000000を超える素数が答えにあるが出力していない
int main(void) {
  unsigned long long A, B;
  cin >> A >> B;
  vector<int> divisor;
  vector<unsigned long long> AHighDiv, BHighDiv;
  for (int i = 1; i <= 1000000; i++) {
    if ((A % i == 0) && (B % i == 0))
      divisor.push_back(i);
    if (A % i == 0) {
      if ((A / i) > 1000000)
        AHighDiv.push_back(A / i);
    }
    if (B % i == 0) {
      if ((B / i) > 1000000)
        BHighDiv.push_back(B / i);
    }
  }

  // 素数リストを作る
  for (int i = 2; i <= 1000000; i++) {
    if (divisorList[i] == 0) {
      for (int j = i * 2; j <= 1000000; j += i) {
        divisorList[j]++;
      }
    }
  }

  int ans = 0;
  for (unsigned int i = 0; i < divisor.size(); i++) {
    if (divisorList[divisor[i]] == 0)
      ans++;
  }
  if ((AHighDiv.size() > 0) && (BHighDiv.size() > 0)) {
    sort(AHighDiv.begin(), AHighDiv.end());
    sort(BHighDiv.begin(), BHighDiv.end());
    int Apos = 0, Bpos = 0;
    while (Apos < AHighDiv.size() && Bpos < BHighDiv.size()) {
      if (AHighDiv[Apos] == BHighDiv[Bpos]) {
        // 素数か確認する
        bool primeNumber = true;
        for (unsigned int i = 2; i < 1000000; i++) {
          if (divisorList[i] == 0) {
            if ((AHighDiv[Apos] % i) == 0) {
              primeNumber = false;
              break;
            }
          }
        }
        if (primeNumber)
          ans++;
        Apos++, Bpos++;
      } else if (AHighDiv[Apos] > BHighDiv[Bpos]) {
        Bpos++;
      } else if (AHighDiv[Apos] < BHighDiv[Bpos]) {
        Apos++;
      }
    }
  }

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