#include <bits/stdc++.h>
using namespace std;
const int N = 200000;
const int Len = 500000;
const long long l1 = 1LL;
bool f[Len + 5];
int A[N + 5], remain[Len + 5];
unordered_map<long long, int> facCount;
vector<int> E[Len + 5];
long long total;
int n, q;
void getPrime() {
  for (int i = 1; i <= Len; ++i) {
    E[i].clear();
    remain[i] = i;
  }
  memset(f, 0, sizeof(f));
  E[2].push_back(2);
  remain[2] = 1;
  for (int i = 4; i <= Len; i += 2) {
    f[i] = true;
    E[i].push_back(2);
    while (remain[i] % 2 == 0) {
      remain[i] /= 2;
    }
  }
  for (int i = 3; i * i <= Len; i += 2) {
    if (!f[i]) {
      E[i].push_back(i);
      remain[i] = 1;
      int tmp = i * i;
      while (tmp <= Len) {
        f[tmp] = true;
        E[tmp].push_back(i);
        while (remain[tmp] % i == 0) {
          remain[tmp] /= i;
        }
        tmp += i;
      }
    }
  }
  for (int i = 1; i <= Len; ++i) {
    if (remain[i] != 1) {
      E[i].push_back(remain[i]);
    }
  }
}
void dfs(int id, int start, long long res, int facs, bool exists) {
  if (start == E[id].size()) {
    if (res != 1) {
      if (exists) {
        --facCount[res];
        if (facs & 1) {
          total -= facCount[res];
        } else {
          total += facCount[res];
        }
      } else {
        if (facs & 1) {
          total += facCount[res];
        } else {
          total -= facCount[res];
        }
        ++facCount[res];
      }
    }
    return;
  }
  dfs(id, start + 1, res, facs, exists);
  dfs(id, start + 1, res * E[id][start], facs + 1, exists);
}
void solve() {
  facCount.clear();
  memset(f, 0, sizeof(f));
  total = 0;
  long long numOfExists = 0;
  while (q--) {
    int x;
    scanf("%d", &x);
    if (!f[x]) {
      ++numOfExists;
      dfs(A[x], 0, 1, 0, 0);
      printf("%I64d\n", numOfExists * (numOfExists - 1) / 2 - total);
      f[x] = true;
    } else {
      --numOfExists;
      dfs(A[x], 0, 1, 0, 1);
      printf("%I64d\n", numOfExists * (numOfExists - 1) / 2 - total);
      f[x] = false;
    }
  }
}
int main() {
  getPrime();
  while (scanf("%d%d", &n, &q) != EOF) {
    for (int i = 1; i <= n; ++i) {
      scanf("%d", &A[i]);
    }
    solve();
  }
  return 0;
}
