#include <bits/stdc++.h>
using namespace std;
int n, q, seq[500010];
bool vis[500010];
long long cnt[500010];
int fac[500010][10], cf[500010];
int cnum[510], c;
long long tot, ans, curans;
void DFS(int num, int pos, int tcnt, int val) {
  if (pos > cf[num]) {
    cnum[c++] = val;
    if (tcnt & 1)
      curans -= cnt[val];
    else
      curans += cnt[val];
    return;
  }
  DFS(num, pos + 1, tcnt, val);
  DFS(num, pos + 1, tcnt + 1, val * fac[num][pos]);
}
void Cal(int num) {
  c = 0;
  curans = 0;
  DFS(num, 1, 0, 1);
}
int main() {
  for (int i = 2; i < 500010; i++) {
    if (cf[i]) continue;
    for (int j = i; j < 500010; j += i) fac[j][++cf[j]] = i;
  }
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) scanf("%d", &seq[i]);
  while (q--) {
    int pos;
    scanf("%d", &pos);
    if (seq[pos] == 1) {
      if (!vis[pos]) {
        vis[pos] = true;
        ans += tot;
        tot++;
        cnt[1]++;
      } else {
        vis[pos] = false;
        ans -= tot - 1;
        tot--;
        cnt[1]--;
      }
      cout << ans << endl;
      continue;
    }
    if (!vis[pos]) {
      vis[pos] = true;
      Cal(seq[pos]);
      ans += curans;
      tot++;
      for (int i = 0; i < c; i++) cnt[cnum[i]]++;
    } else {
      vis[pos] = false;
      Cal(seq[pos]);
      tot--;
      ans -= curans;
      for (int i = 0; i < c; i++) cnt[cnum[i]]--;
    }
    cout << ans << endl;
  }
  return 0;
}
