#include <bits/stdc++.h>
using namespace std;
int P[500000 + 5];
void sieve() {
  memset(P, -1, sizeof(P));
  for (int i = 2; i * i <= 500000; ++i)
    if (P[i] == -1)
      for (int j = i * i; j <= 500000; j += i) P[j] = i;
}
void primefact(int n, vector<int> &pr, vector<int> &ex) {
  while (1) {
    int p = P[n];
    if (n == 1) {
      return;
    }
    if (p == -1) {
      pr.push_back(n), ex.push_back(1);
      break;
    }
    int exp = 0;
    while (n % p == 0) {
      exp++;
      n /= p;
    }
    pr.push_back(p), ex.push_back(exp);
  }
}
vector<int> get(vector<int> pr, vector<int> ex) {
  int k = pr.size();
  vector<int> divisors(1, 1);
  for (int i = 0; i < k; ++i) {
    int m = divisors.size();
    for (int j = 0; j < ex[i]; ++j)
      for (int a = 0; a < m; ++a)
        divisors.push_back(pr[i] * divisors[a + j * m]);
  }
  return divisors;
}
long long mu[500000 + 5];
int getMu(int n) {
  int cnt = 0;
  while (1) {
    int p = P[n];
    if (n == 1) {
      break;
    }
    if (p == -1) {
      cnt++;
      break;
    }
    int exp = 0;
    while (n % p == 0) {
      exp++;
      n /= p;
    }
    if (exp > 1) return 0;
    cnt++;
  }
  if (cnt & 1) return -1;
  return 1;
}
long long S;
long long f(long long n) { return (n * (n - 1)) / 2LL; }
long long freq[500000 + 5];
long long g(long long n) { return f(freq[n]) * mu[n]; }
int main() {
  sieve();
  for (int i = 1; i <= 500000; ++i) mu[i] = getMu(i);
  int n;
  while (scanf("%d", &n) == 1) {
    memset(freq, 0, sizeof(freq));
    int Q, m = 0;
    scanf("%d", &Q);
    vector<int> a(n), used(n);
    for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
    S = 0, m = 0;
    for (int it = 0; it < Q; ++it) {
      int pos;
      scanf("%d", &pos);
      pos--;
      vector<int> p, e;
      primefact(a[pos], p, e);
      vector<int> DIV = get(p, e);
      for (int d : DIV) {
        if (d == 1) continue;
        S -= g(d);
        if (!used[pos])
          freq[d]++;
        else
          freq[d]--;
        S += g(d);
      }
      if (used[pos])
        m--;
      else
        m++;
      used[pos] ^= 1;
      cout << f(m) + S << endl;
    }
  }
}
