#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool rd(T &ret) {
  char c;
  int sgn;
  if (c = getchar(), c == EOF) return 0;
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  sgn = (c == '-') ? -1 : 1;
  ret = (c == '-') ? 0 : (c - '0');
  while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
  ret *= sgn;
  return 1;
}
template <class T>
inline void pt(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9) pt(x / 10);
  putchar(x % 10 + '0');
}
const int N = 5e5 + 10;
int prime[N], primenum;
void PRIME(long long Max_Prime) {
  primenum = 0;
  prime[primenum++] = 2;
  for (long long i = 3; i <= Max_Prime; i += 2)
    for (long long j = 0; j < primenum; j++)
      if (i % prime[j] == 0)
        break;
      else if (prime[j] > sqrt((double)i) || j == primenum - 1) {
        prime[primenum++] = i;
        break;
      }
}
int n, q;
int a[N];
vector<int> G[N];
long long ans;
void pre(int u, int x) {
  for (int i = 0; prime[i] * prime[i] <= x; i++) {
    if (x % prime[i] == 0) {
      while (x % prime[i] == 0) x /= prime[i];
      G[u].push_back(prime[i]);
    }
  }
  if (x != 1) G[u].push_back(x);
}
set<int> s;
int f[N];
int c[N], top;
void dfs(int t, int x, int cnt, int flag, int val) {
  if (t >= (int)G[x].size()) {
    if (cnt == 0) return;
    ans += f[val] * flag;
    c[top++] = val;
    return;
  }
  dfs(t + 1, x, cnt, flag, val);
  dfs(t + 1, x, cnt + 1, flag * -1, val * G[x][t]);
}
void p() {
  printf(" set:");
  for (auto it : s) {
    printf("%d ", it);
  }
  puts("");
}
int one;
int main() {
  PRIME(N);
  rd(n);
  rd(q);
  for (int i = 1; i <= n; i++) {
    rd(a[i]);
    pre(i, a[i]);
  }
  ans = 0;
  one = 0;
  while (q--) {
    int u;
    rd(u);
    if (a[u] == 1) {
      if (s.count(u)) {
        one--;
        s.erase(u);
        ans -= s.size();
      } else {
        ans += s.size();
        one++;
        s.insert(u);
      }
    } else {
      if (s.count(u)) {
        s.erase(u);
        ans -= s.size();
        top = 0;
        dfs(0, u, 0, -1, 1);
        ans--;
        for (int i = 0; i < top; i++) f[c[i]]--;
      } else {
        ans += s.size();
        s.insert(u);
        top = 0;
        dfs(0, u, 0, 1, 1);
        for (int i = 0; i < top; i++) f[c[i]]++;
      }
    }
    cout << "   ";
    pt(ans);
    puts("");
  }
  return 0;
}
