#include <bits/stdc++.h>
using namespace std;
int f[500500];
int v[500500];
vector<int> divs[500500];
vector<int> sqfdivs[500500];
int ord[500500];
int sieve[500500];
int legal[500500];
int state[500500];
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  for (int i = 0; i < n; i++) scanf("%d", v + i);
  long long ans = 0;
  for (int i = 2; i <= 500000; i++)
    if (sieve[i] == 0) {
      sieve[i] = i;
      for (int j = 2 * i; j <= 500000; j += i) sieve[j] = i;
    }
  ord[1] = 1;
  sieve[1] = 1;
  legal[1] = 1;
  for (int i = 2; i <= 500000; i++) {
    long long p = sieve[i];
    if (i % (p * p) != 0 && legal[i / p]) legal[i] = 1;
    if (i == 2) assert(legal[i]);
    if (!legal[i]) continue;
    ord[i] = -ord[i / p];
    for (int j = i; j <= 500000; j += i) sqfdivs[j].push_back(i);
  }
  int on = 0;
  while (q--) {
    int u;
    scanf("%d", &u), u--;
    if (state[u] == 0) {
      state[u] = 1;
      long long inc = on;
      int t = v[u];
      for (vector<int>::iterator it = sqfdivs[t].begin(); it < sqfdivs[t].end();
           it++)
        inc += f[*it] * ord[*it];
      for (vector<int>::iterator it = sqfdivs[t].begin(); it < sqfdivs[t].end();
           it++)
        f[*it]++;
      ans += inc;
      printf("%I64d\n", ans);
      on++;
      continue;
    }
    state[u] = 0;
    on--;
    long long inc = on;
    int t = v[u];
    for (vector<int>::iterator it = sqfdivs[t].begin(); it < sqfdivs[t].end();
         it++)
      f[*it]--;
    for (vector<int>::iterator it = sqfdivs[t].begin(); it < sqfdivs[t].end();
         it++)
      inc += f[*it] * ord[*it];
    ans -= inc;
    printf("%I64d\n", ans);
  }
}
