#include <bits/stdc++.h>
std::vector<int> d[500024];
int a[500024], n, m, x;
int mu[500024], cnt[500024], vis[500024];
long long ans = 0;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (1), __ = (n); i <= __; ++i) {
    scanf("%d", a + i);
    vis[a[i]] = 1;
  }
  mu[1] = 1;
  for (int i = (1), __ = (500000); i <= __; ++i) {
    for (int j = i; j < 500000; j += i) {
      if (vis[j]) d[j].push_back(i);
      if (i != j) mu[j] -= mu[i];
    }
  }
  memset(vis, 0, sizeof vis);
  while (m--) {
    scanf("%d", &x);
    if (!vis[x])
      for (int i = (0), __ = (d[a[x]].size()); i < __; ++i) {
        ans += (long long)(mu[d[a[x]][i]] * (cnt[d[a[x]][i]]++));
      }
    else {
      for (int i = (0), __ = (d[a[x]].size()); i < __; ++i) {
        ans -= (long long)(mu[d[a[x]][i]] * (--cnt[d[a[x]][i]]));
      }
    }
    vis[x] ^= 1;
    std::cout << ans << "\n";
  }
  return 0;
}
