#include <bits/stdc++.h>
using namespace std;
long long int a[1000005], mobius[1000005], multiples[1000005], prime[1000005],
    ans, on[1000005];
vector<long long int> prime_factor[1000005];
void add(long long int pos) {
  long long int val = a[pos];
  for (long long int i = 1; i * i <= val; i++) {
    if (val % i) continue;
    ans = ans - mobius[i] * multiples[i] * (multiples[i] - 1) / 2;
    multiples[i]++;
    ans = ans + mobius[i] * multiples[i] * (multiples[i] - 1) / 2;
    if (val / i == i) continue;
    ans = ans -
          mobius[val / i] * multiples[val / i] * (multiples[val / i] - 1) / 2;
    multiples[val / i]++;
    ans = ans +
          mobius[val / i] * multiples[val / i] * (multiples[val / i] - 1) / 2;
  }
}
void remov(long long int pos) {
  long long int val = a[pos];
  for (long long int i = 1; i * i <= val; i++) {
    if (val % i) continue;
    ans = ans - mobius[i] * multiples[i] * (multiples[i] - 1) / 2;
    multiples[i]--;
    ans = ans + mobius[i] * multiples[i] * (multiples[i] - 1) / 2;
    if (val / i == i) continue;
    ans = ans -
          mobius[val / i] * multiples[val / i] * (multiples[val / i] - 1) / 2;
    multiples[val / i]--;
    ans = ans +
          mobius[val / i] * multiples[val / i] * (multiples[val / i] - 1) / 2;
  }
}
int main() {
  ios::sync_with_stdio(false);
  ;
  cin.tie(0);
  ;
  long long int i, j, n, q, pos;
  for (i = 1; i <= 1000000; i++) mobius[i] = -1;
  mobius[1] = 1;
  for (i = 2; i <= 1000000; i++) {
    if (prime[i]) continue;
    for (j = i; j <= 1000000; j += i) {
      if (j != i) prime[j] = 1;
      prime_factor[j].push_back(i);
      long long int ctr = 0;
      long long int tj = j;
      while (tj % i == 0) {
        tj /= i;
        ctr++;
      }
      if (ctr > 1) mobius[j] = 0;
    }
  }
  for (i = 2; i <= 1000000; i++) {
    if (mobius[i] == -1) {
      if (prime_factor[i].size() % 2)
        mobius[i] = -1;
      else
        mobius[i] = 1;
    }
  }
  cin >> n >> q;
  for (i = 1; i <= n; i++) cin >> a[i];
  while (q--) {
    cin >> pos;
    on[pos] = 1 - on[pos];
    if (on[pos])
      add(pos);
    else
      remov(pos);
    cout << ans << "\n";
  }
  return 0;
}
