#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int N = 5e5 + 15;
ll cnt[N];
int is[N];
int a[N];
vector<int> orz(int a) {
  vector<int> ret;
  for (int i = 2; i * i <= a; ++i) {
    if (a % i) continue;
    ret.push_back(i);
    while (a % i == 0) a /= i;
  }
  if (a > 1) ret.push_back(a);
  return ret;
}
int get_bits(int mask) {
  int s = 0;
  while (mask) s++, mask &= (mask - 1);
  return s;
}
ll getN(ll k) {
  auto it = orz(k);
  ll res = 0;
  for (int mask = 1; mask < (1 << it.size()); ++mask) {
    ll lcm = 1;
    int bits = 0;
    for (int j = 0; j < it.size(); ++j) {
      if (mask & (1 << j)) lcm *= it[j], bits++;
    }
    if (bits % 2) {
      res += cnt[lcm];
    } else {
      res -= cnt[lcm];
    }
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  int n, q;
  cin >> n >> q;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  int sz = 0;
  ll cur = 0;
  while (q--) {
    int k;
    cin >> k;
    int num = k;
    if (is[k]) {
      k = a[k];
      for (int i = 1; i * i <= k; ++i) {
        if (k % i == 0) {
          cnt[i]--;
          if (k / i != i) cnt[k / i]--;
        }
      }
      sz--;
      ll f = sz;
      f -= getN(k);
      cur -= f;
    } else {
      k = a[k];
      ll f = sz;
      f -= getN(k);
      cur += f;
      for (int i = 1; i * i <= k; ++i) {
        if (k % i == 0) {
          cnt[i]++;
          if (k / i != i) cnt[k / i]++;
        }
      }
      sz++;
    }
    is[num] ^= 1;
    cout << cur << "\n";
  }
  return 0;
}
