#include <bits/stdc++.h>
using namespace std;
const int MAX = 5e5 + 7;
int n, q;
int a[MAX];
bool present[MAX];
vector<int> d[MAX];
long long ans;
int multiple_count[MAX];
int IN;
void gen() {
  for (int i = 2; i < MAX; i++)
    if (d[i].size() == 0)
      for (int j = 1; i * j < MAX; j++) d[j * i].push_back(i);
}
void Remove(int I) {
  int val = 0;
  present[I] = false;
  int sz = d[a[I]].size();
  for (int i = 1; i < (1 << sz); i++) {
    int p = 1, c = 0;
    for (int j = 0; j < sz; j++)
      if (i & (1 << j)) {
        c++;
        p = p * d[a[I]][j];
      }
    multiple_count[p]--;
    if (c % 2 == 1)
      val += multiple_count[p];
    else
      val -= multiple_count[p];
  }
  IN--;
  ans -= IN - val;
}
void Insert(int I) {
  int val = 0;
  present[I] = true;
  int sz = d[a[I]].size();
  for (int i = 1; i < (1 << sz); i++) {
    int p = 1, c = 0;
    for (int j = 0; j < sz; j++)
      if (i & (1 << j)) {
        c++;
        p = p * d[a[I]][j];
      }
    if (c % 2 == 1)
      val += multiple_count[p];
    else
      val -= multiple_count[p];
    multiple_count[p]++;
  }
  ans += IN - val;
  IN++;
}
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  gen();
  while (q--) {
    int x;
    scanf("%d", &x);
    if (present[x])
      Remove(x);
    else
      Insert(x);
    printf("%I64d\n", ans);
  }
  return 0;
}
