#include <bits/stdc++.h>
using namespace std;
const long long MAX_N = 5e5 + 25;
long long n, q, ans, num;
long long Arr[MAX_N];
bool in[MAX_N];
long long cnt[MAX_N];
void upd(long long x, long long type) {
  vector<long long> k;
  long long d = 2;
  for (long long i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      k.push_back(i);
      while (x % i == 0) x /= i;
    }
  }
  if (x != 1) k.push_back(x);
  for (long long i = 1; i < (1 << k.size()); i++) {
    long long tmp = 1;
    for (long long j = 0; j < k.size(); j++)
      if ((i >> j) & 1) tmp *= k[j];
    cnt[tmp] += type;
  }
}
long long calc(long long x) {
  vector<long long> k;
  long long d = 2;
  for (long long i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      k.push_back(i);
      while (x % i == 0) x /= i;
    }
  }
  if (x != 1) k.push_back(x);
  long long res = 0;
  for (long long i = 1; i < (1 << k.size()); i++) {
    long long tmp = 1;
    for (long long j = 0; j < k.size(); j++)
      if ((i >> j) & 1) tmp *= k[j];
    res += (__builtin_popcount(i) & 1 ? cnt[tmp] : -cnt[tmp]);
  }
  return num - res;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> q;
  for (long long i = 1; i <= n; i++) cin >> Arr[i];
  while (q--) {
    long long ind;
    cin >> ind;
    if (in[ind]) {
      upd(Arr[ind], -1);
      num--;
      ans -= calc(Arr[ind]);
    } else {
      ans += calc(Arr[ind]);
      upd(Arr[ind], +1);
      num++;
    }
    in[ind] ^= 1;
    cout << ans << "\n";
  }
  return 0;
}
