#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int LIM = 5e5;
long long sol;
int n, m, q, a[N], mark[LIM + 10], dp[LIM];
bool add[N];
void sieve() {
  for (int i = 3; i <= LIM; i += 2) {
    mark[i - 1] = 2;
    if (!mark[i]) {
      mark[i] = i;
      if (i <= sqrt(LIM) + 1)
        for (int j = i * i; j <= LIM; j += i)
          if (!mark[j]) mark[j] = i;
    }
  }
}
inline vector<int> factor(int x) {
  vector<int> ret = {};
  while (x > 1) {
    int curPrime = mark[x];
    while (x % curPrime == 0) x /= curPrime;
    ret.push_back(curPrime);
  }
  return ret;
}
inline int product(const vector<int> &p, int mask, int k) {
  int ret = 1;
  for (int i = 0; i < k; i++)
    if (mask & (1 << i)) ret *= p[i];
  return ret;
}
inline void addNumber(int idx) {
  add[idx] = true;
  vector<int> p = factor(a[idx]);
  int k = (int)(p.size());
  int cnt = 0;
  for (int mask = 1; mask < (1 << k); mask++) {
    int state = product(p, mask, k);
    if (__builtin_popcount(mask) & 1)
      cnt += dp[state]++;
    else
      cnt -= dp[state]++;
  }
  sol += 1ll * (m - cnt);
  m++;
}
inline void delNumber(int idx) {
  add[idx] = false;
  vector<int> p = factor(a[idx]);
  int k = (int)(p.size());
  int cnt = 0;
  for (int mask = 1; mask < (1 << k); mask++) {
    int state = product(p, mask, k);
    if (__builtin_popcount(mask) & 1)
      cnt += --dp[state];
    else
      cnt -= --dp[state];
  }
  m--;
  sol -= 1ll * (m - cnt);
}
int main() {
  sieve();
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  while (q--) {
    int idx;
    scanf("%d", &idx);
    if (!add[idx])
      addNumber(idx);
    else
      delNumber(idx);
    printf("%lld\n", sol);
  }
  return 0;
}
