#include <bits/stdc++.h>
using namespace std;
const int maxn = 500005;
int n, q;
int a[maxn];
int prim[maxn];
vector<int> g[maxn];
int cnt[maxn];
bool vis[maxn];
int use[maxn];
void init() {
  for (int i = 2; i < maxn; i++)
    if (!vis[i]) {
      for (int j = i; j < maxn; j += i) {
        vis[j] = 1;
        g[j].push_back(i);
      }
    }
}
int main() {
  init();
  cin >> n >> q;
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  long long ans = 0;
  while (q--) {
    int x;
    scanf("%d", &x);
    int st = 1 << g[a[x]].size();
    int res = 0;
    for (int i = 0; i < st; i++) {
      int now = 1, c = 0;
      for (int j = 0; j < g[a[x]].size(); j++)
        if (i >> j & 1) {
          now *= g[a[x]][j];
          c++;
        }
      if (c & 1)
        res -= cnt[now];
      else
        res += cnt[now];
    }
    if (!use[x]) {
      use[x] = 1;
      ans += res;
      for (int i = 0; i < st; i++) {
        int now = 1;
        for (int j = 0; j < g[a[x]].size(); j++)
          if (i >> j & 1) {
            now *= g[a[x]][j];
          }
        cnt[now]++;
      }
    } else {
      use[x] = 0;
      if (a[x] == 1) ans++;
      ans -= res;
      for (int i = 0; i < st; i++) {
        int now = 1;
        for (int j = 0; j < g[a[x]].size(); j++)
          if (i >> j & 1) {
            now *= g[a[x]][j];
          }
        cnt[now]--;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
