#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFF = 0x3f3f;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-9;
const long long mod = 1e9 + 7;
const unsigned long long mxx = 1333331;
inline void RI(int &x) {
  char c;
  while ((c = getchar()) < '0' || c > '9')
    ;
  x = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0';
}
int a[200005];
int g[500005];
set<int> s;
bool prime[500005];
int pr[500005];
int tot;
vector<int> v;
void init() {
  memset(prime, 0, sizeof(prime));
  tot = 0;
  for (int i = 2; i < 500005; i++) {
    if (!prime[i]) {
      for (int j = 2 * i; j < 500005; j += i) prime[j] = 1;
      pr[tot++] = i;
    }
  }
}
int main() {
  int n, q;
  init();
  while (~scanf("%d%d", &n, &q)) {
    s.clear();
    memset(g, 0, sizeof(g));
    int maxn = 0;
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    long long ans = 0;
    while (q--) {
      int x;
      scanf("%d", &x);
      v.clear();
      int cnt = s.size();
      if (s.count(x)) {
        for (int i = 1; i * i <= a[x]; i++) {
          if (a[x] % i == 0) {
            g[i]--;
            if (a[x] / i != i) g[a[x] / i]--;
          }
        }
        cnt--;
      }
      int k = a[x];
      for (int i = 0; i < tot && pr[i] * pr[i] <= k; i++) {
        if (k % pr[i] == 0) {
          v.push_back(pr[i]);
          while (k % pr[i] == 0) k /= pr[i];
        }
      }
      if (k != 1) v.push_back(k);
      long long ret = 0;
      for (int i = 1; i < (1 << v.size()); i++) {
        int tmp = 1;
        for (int j = 0; j < v.size(); j++) {
          if ((1 << j) & i) tmp *= v[j];
        }
        int num = __builtin_popcount(i);
        if (num % 2)
          ret += g[tmp];
        else
          ret -= g[tmp];
      }
      if (s.count(x)) {
        ans -= (cnt - ret);
        s.erase(x);
      } else {
        ans += (cnt - ret);
        s.insert(x);
        for (int i = 1; i * i <= a[x]; i++) {
          if (a[x] % i == 0) {
            g[i]++;
            if (a[x] / i != i) g[a[x] / i]++;
          }
        }
      }
      printf("%I64d\n", ans);
    }
  }
  return 0;
}
