#include <bits/stdc++.h>
using namespace std;
const int maxv = 500005;
int notp[maxv];
vector<int> pl;
void prime() {
  for (int q = 2; q < maxv; q++) {
    if (!notp[q]) pl.push_back(notp[q] = q);
    for (auto p : pl) {
      int x = p * q;
      if (x >= maxv) break;
      notp[x] = p;
      if (q % p == 0) break;
    }
  }
}
const int maxn = 200005;
int n, q;
int ar[maxn];
void read() {
  scanf("%d%d", &n, &q);
  for (int i = 0; i < n; i++) scanf("%d", &ar[i]);
}
vector<pair<int, int> > p[maxn];
void build() {
  for (int i = 0; i < n; i++) {
    vector<int> fac;
    int x = ar[i];
    while (x > 1) {
      fac.push_back(notp[x]);
      while (x % fac.back() == 0) x /= fac.back();
    }
    int siz = fac.size();
    for (int s = 1; s < (1 << siz); s++) {
      int val = 1, cnt = 0;
      for (int j = 0; j < siz; j++)
        if (s & (1 << j)) val *= fac[j], cnt++;
      p[i].push_back(make_pair(val, (cnt & 1) ? 1 : -1));
    }
  }
}
struct Seg {
  struct Node {
    Node() : sum(0), joe(-1), l(0), r(0) {}
    Node(int j) : sum(0), joe(j), l(0), r(0) {}
    int sum, joe;
    Node *l, *r;
  } * root;
  inline int sum(Node *o) { return o ? o->sum : 0; }
  void update(Node *&o, int low, int high, int pos, int val) {
    if (!o) o = new Node(pos);
    if (low == high || o->joe == pos) {
      o->sum = val;
      return;
    }
    int mid = (low + high) / 2;
    if (~o->joe) {
      int j = o->joe;
      o->joe = -1;
      if (j <= mid) {
        o->l = new Node(j);
        o->l->sum = o->sum;
      } else {
        o->r = new Node(j);
        o->r->sum = o->sum;
      }
    }
    if (pos <= mid)
      update(o->l, low, mid, pos, val);
    else
      update(o->r, mid + 1, high, pos, val);
    o->sum = sum(o->l) + sum(o->r);
  }
  int query() { return sum(root); }
} seg[maxv];
bitset<maxn> app;
void sol() {
  long long ans = 0;
  int tot = 0;
  while (q--) {
    int x;
    scanf("%d", &x);
    x--;
    if (app[x] == 0) {
      app[x] = 1;
      ans += tot;
      tot++;
      for (auto val : p[x]) ans -= seg[val.first].query() * val.second;
      for (auto val : p[x])
        seg[val.first].update(seg[val.first].root, 0, n - 1, x, 1);
    } else {
      app[x] = 0;
      tot--;
      ans -= tot;
      for (auto val : p[x])
        seg[val.first].update(seg[val.first].root, 0, n - 1, x, 0);
      for (auto val : p[x]) ans += seg[val.first].query() * val.second;
    }
    printf("%lld\n", ans);
  }
}
int main() {
  prime();
  read();
  build();
  sol();
  return 0;
}
