#include <bits/stdc++.h>
using namespace std;
int cnt[500005];
bool here[200005];
vector<int> primes, v[500005];
void get_primes(long long MAX) {
  bool visited[MAX + 10];
  memset(visited, 0, sizeof(visited));
  for (long long x = 2; x <= MAX; x++)
    if (!visited[x]) {
      primes.push_back(x);
      for (long long j = x * x; j <= MAX; j += x) visited[j] = true;
    }
}
int main() {
  ios_base::sync_with_stdio(0);
  int m, q, x, n;
  cin >> m >> q;
  get_primes(710);
  for (int i = 0; i < m; i++) {
    cin >> x;
    for (int j = 0; primes[j] * 1LL * primes[j] <= x; j++) {
      if (x % primes[j] == 0) v[i].push_back(primes[j]);
      while (x % primes[j] == 0) x /= primes[j];
    }
    if (x != 1) v[i].push_back(x);
  }
  long long res = 0;
  m = 0;
  while (q--) {
    cin >> x;
    x--;
    n = v[x].size();
    int c = 0;
    for (int i = 1; i < (1 << n); i++) {
      bool second = (__builtin_popcount(i) & 1);
      int y = 1;
      for (int j = 0; j < n; j++) {
        if ((i & (1 << j)) == 0) continue;
        y *= v[x][j];
      }
      if (second)
        c += cnt[y];
      else
        c -= cnt[y];
    }
    for (int i = 1; i < (1 << n); i++) {
      int y = 1;
      for (int j = 0; j < n; j++) {
        if ((i & (1 << j)) == 0) continue;
        y *= v[x][j];
      }
      if (here[x])
        cnt[y]--;
      else
        cnt[y]++;
    }
    if (v[x].size() == 0 && here[x]) c++;
    c = m - c;
    if (here[x])
      res -= c;
    else
      res += c;
    if (here[x])
      m--;
    else
      m++;
    here[x] = !here[x];
    cout << res << "\n";
  }
  return 0;
}
