#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 9;
bool onshelf[MAXN];
long long sprime[MAXN], arr[MAXN];
long long pairs = 0, commonprime = 0;
long long cnt[MAXN], idx;
long long N, Q, szshelf = 0;
inline void sieve() {
  memset(sprime, -1, sizeof(sprime));
  for (long long i = 2; i <= MAXN - 3; ++i)
    if (sprime[i] == -1)
      for (long long j = i * i; j <= MAXN - 3; j += i) sprime[j] = i;
  for (int i = 2; i <= MAXN - 3; ++i) {
    if (sprime[i] == -1) sprime[i] = i;
  }
}
int main() {
  sieve();
  memset(onshelf, false, sizeof(onshelf));
  memset(arr, 0, sizeof(arr));
  memset(cnt, 0, sizeof(cnt));
  cin >> N >> Q;
  for (int i = 1; i <= N; ++i) cin >> arr[i];
  while (Q--) {
    cin >> idx;
    if (!onshelf[idx]) {
      onshelf[idx] = true;
      ++szshelf;
      long long cur = arr[idx];
      vector<long long> factors;
      while (cur > 1) {
        long long div = sprime[cur];
        factors.push_back(div);
        while (cur % div == 0) cur = cur / div;
      }
      if (arr[idx] == 1) {
        long long totalpairs = szshelf * (szshelf - 1) / 2LL;
        long long ans = totalpairs - commonprime;
        cout << ans << endl;
      } else {
        long long n = (long long)factors.size();
        for (long long mask = 1; mask < (1 << n); ++mask) {
          int masksize = __builtin_popcount(mask);
          long long val = 1LL;
          for (int j = 0; j < n; ++j) {
            if (mask & (1 << j)) val = val * 1LL * factors[j];
          }
          if (masksize & 1)
            commonprime += cnt[val];
          else
            commonprime -= cnt[val];
          cnt[val]++;
        }
        long long totalpairs = szshelf * (szshelf - 1) / 2LL;
        long long ans = totalpairs - commonprime;
        cout << ans << endl;
      }
    } else {
      onshelf[idx] = false;
      szshelf--;
      long long cur = arr[idx];
      vector<long long> factors;
      while (cur > 1) {
        long long div = sprime[cur];
        factors.push_back(div);
        while (cur % div == 0) cur = cur / div;
      }
      if (arr[idx] == 1) {
        long long totalpairs = szshelf * (szshelf - 1) / 2LL;
        long long ans = totalpairs - commonprime;
        cout << ans << endl;
      } else {
        long long n = (long long)factors.size();
        for (long long mask = 1; mask < (1 << n); ++mask) {
          int masksize = __builtin_popcount(mask);
          long long val = 1LL;
          for (int j = 0; j < n; ++j) {
            if (mask & (1 << j)) val = val * 1LL * factors[j];
          }
          cnt[val]--;
          if (masksize & 1)
            commonprime -= cnt[val];
          else
            commonprime += cnt[val];
        }
        long long totalpairs = szshelf * (szshelf - 1) / 2LL;
        long long ans = totalpairs - commonprime;
        cout << ans << endl;
      }
    }
  }
  return 0;
}
