#include <bits/stdc++.h>
using namespace std;
int arr[200005];
bool shelf[200005];
map<int, int> cnt;
long long common(int n, bool add) {
  int nf = 0;
  int facts[10];
  for (int i = 2; i * i <= n && n > 1; i++) {
    if (n % i == 0) {
      facts[nf] = i;
      while (n % i == 0) {
        n /= i;
      }
      nf++;
    }
  }
  if (n > 1) {
    facts[nf] = n;
    nf++;
  }
  long long pairs = 0;
  for (int i = 1; i < (1 << nf); ++i) {
    int num = 1, sgn = -1;
    for (int j = 0; j < nf; ++j) {
      if ((i >> j) & 1) {
        num *= facts[j];
        sgn *= -1;
      }
    }
    cnt[num] += add ? 1 : -1;
    pairs += sgn * cnt[num];
  }
  if (nf > 0 && add) pairs--;
  return pairs;
}
int main() {
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  long long ans = 0;
  int nshelf = 0;
  for (int i = 0; i < q; ++i) {
    int x;
    cin >> x;
    x--;
    if (!shelf[x]) {
      shelf[x] = true;
      nshelf++;
      ans += nshelf - 1 - common(arr[x], true);
    } else {
      shelf[x] = false;
      nshelf--;
      ans -= nshelf - common(arr[x], false);
    }
    cout << ans << endl;
  }
  return 0;
}
