#include <bits/stdc++.h>
using namespace std;
const int Maxn = 200005, Maxm = 500005;
int n, q, a[Maxn], Prime[Maxm], cnt[Maxm];
bool vis[Maxn];
vector<int> b[Maxn];
inline int Getint() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) ch != '-' ?: f = -1, ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
long long lcm(long long x, long long y) { return x / gcd(x, y) * y; }
void init() {
  static bool no_prime[Maxm];
  for (int i = 2; i <= 500000; i++) {
    if (!no_prime[i]) Prime[++Prime[0]] = i;
    for (int j = 1; j <= Prime[0] && i * Prime[j] <= 500000; j++) {
      no_prime[i * Prime[j]] = 1;
      if (i % Prime[j] == 0) break;
    }
  }
}
int main() {
  init();
  n = Getint();
  q = Getint();
  for (int i = 1; i <= n; i++) {
    a[i] = Getint();
    int x = a[i];
    for (int j = 1; j <= Prime[0] && Prime[j] * Prime[j] <= x; j++)
      if (x % Prime[j] == 0) {
        b[i].push_back(Prime[j]);
        while (x % Prime[j] == 0) x /= Prime[j];
      }
    if (x != 1) b[i].push_back(x);
  }
  long long ans = 0, now = 0;
  while (q--) {
    int x = Getint();
    vis[x] ^= 1;
    if (vis[x]) {
      long long tmp = 0;
      int tot = b[x].size();
      for (int i = 1; i < (1 << tot); i++) {
        int f = (__builtin_popcount(i) & 1) ? 1 : -1;
        long long lcm = 1;
        for (int j = 0; j < tot; j++)
          if (i & (1 << j)) {
            lcm = ::lcm(lcm, b[x][j]);
            if (lcm > 500000) break;
          }
        if (lcm <= 500000) tmp += f * cnt[lcm];
      }
      for (int i = 1; i * i <= a[x]; i++)
        if (a[x] % i == 0) {
          cnt[i]++;
          if (i * i != a[x]) cnt[a[x] / i]++;
        }
      ans += tmp;
      now++;
      cout << (now - 1) * now / 2 - ans << "\n";
    } else {
      for (int i = 1; i * i <= a[x]; i++)
        if (a[x] % i == 0) {
          cnt[i]--;
          if (i * i != a[x]) cnt[a[x] / i]--;
        }
      int tot = b[x].size();
      long long tmp = 0;
      for (int i = 1; i < (1 << tot); i++) {
        int f = (__builtin_popcount(i) & 1) ? 1 : -1;
        long long lcm = 1;
        for (int j = 0; j < tot; j++)
          if (i & (1 << j)) {
            lcm = ::lcm(lcm, b[x][j]);
            if (lcm > 500000) break;
          }
        if (lcm <= 500000) tmp += f * cnt[lcm];
      }
      ans -= tmp;
      now--;
      cout << now * (now - 1) / 2 - ans << "\n";
    }
  }
}
