#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 0x3f3f3f3f;
const int maxn = 5e5 + 5;
const int N = 5e5 + 5;
const int mod = 1073741824;
int prime[N], tot;
bool notprime[N];
int mu[N];
vector<int> factor[N];
void getprime() {
  mu[1] = 1;
  for (int i = 2; i < N; i++) {
    if (!notprime[i]) {
      prime[++tot] = i;
      mu[i] = -1;
    }
    for (int j = 1; j <= tot && prime[j] * i < N; j++) {
      int x = prime[j] * i;
      notprime[x] = true;
      if (i % prime[j] == 0) {
        break;
      } else {
        mu[x] = -mu[i];
      }
    }
  }
  for (int i = 1; i < N; i++)
    for (int j = i; j < N; j += i) factor[j].push_back(i);
}
int a[maxn];
int cnt[maxn];
bool in[maxn];
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  getprime();
  int n, q;
  ll ans = 0;
  cin >> n >> q;
  for (int i = 1; i <= n; i++) cin >> a[i];
  while (q--) {
    int x;
    cin >> x;
    if (in[x]) {
      in[x] = 0;
      x = a[x];
      int res = 0;
      for (auto &y : factor[x]) {
        res += mu[y] * cnt[y];
        cnt[y]--;
      }
      ans -= res;
      if (x == 1) ans++;
    } else {
      in[x] = 1;
      x = a[x];
      int res = 0;
      for (auto &y : factor[x]) {
        res += mu[y] * cnt[y];
        cnt[y]++;
      }
      ans += res;
    }
    cout << ans << "\n";
  }
  return 0;
}
