#include <bits/stdc++.h>
using namespace std;
int const MAX = 5e5 + 5;
int p[MAX], mob[MAX], a[MAX], cnt[MAX];
bool prime[MAX], vis[MAX], has[MAX];
vector<int> vt[MAX];
void Mobius() {
  int pnum = 0;
  mob[1] = 1;
  for (int i = 2; i < MAX; i++) {
    if (!prime[i]) {
      p[pnum++] = i;
      mob[i] = -1;
    }
    for (int j = 0; j < pnum && i * p[j] < MAX; j++) {
      prime[i * p[j]] = true;
      if (i % p[j] == 0) {
        mob[i * p[j]] = 0;
        break;
      }
      mob[i * p[j]] = -mob[i];
    }
  }
}
int main() {
  Mobius();
  int n, q, idx, ma = 0;
  scanf("%d %d", &n, &q);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    has[a[i]] = true;
    ma = max(ma, a[i]);
  }
  for (int i = 1; i <= ma; i++)
    for (int j = i; j <= ma; j += i)
      if (has[j]) vt[j].push_back(i);
  long long ans = 0;
  while (q--) {
    scanf("%d", &idx);
    if (!vis[idx]) {
      vis[idx] = true;
      for (int i = 0; i < (int)vt[a[idx]].size(); i++) {
        int num = vt[a[idx]][i];
        ans += (long long)mob[num] * cnt[num];
        cnt[num]++;
      }
    } else {
      vis[idx] = false;
      for (int i = 0; i < (int)vt[a[idx]].size(); i++) {
        int num = vt[a[idx]][i];
        cnt[num]--;
        ans -= (long long)mob[num] * cnt[num];
      }
    }
    printf("%I64d\n", ans);
  }
}
