#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)(5e5) + 2;
const int mod = (int)(1e9) + 7;
int n, q, a[maxn], cn[maxn];
bool was[maxn];
vector<int> p[maxn];
void add(int id, int mul) {
  cn[1] += mul;
  for (int mask = 1; mask < (1 << p[id].size()); mask++) {
    int h = 1;
    for (int i = 0; i < p[id].size(); i++) {
      if (mask & (1 << i)) h *= p[id][i];
    }
    cn[h] += mul;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> q;
  for (int i = 1, x; i <= n; i++) {
    cin >> x;
    int j = 2;
    while (j * j <= x) {
      if (x % j == 0) p[i].push_back(j);
      while (x % j == 0) x /= j;
      j++;
    }
    if (x > 1) p[i].push_back(x);
  }
  long long res = 0;
  for (int i = 1, x; i <= q; ++i) {
    cin >> x;
    int mul = (was[x] ? -1 : 1);
    if (mul == -1) add(x, mul);
    res += mul * cn[1];
    for (int mask = 1; mask < (1 << p[x].size()); mask++) {
      int h = 1;
      int z = 0;
      for (int j = 0; j < p[x].size(); j++) {
        if (mask & (1 << j)) {
          h *= p[x][j];
          z ^= 1;
        }
      }
      if (z)
        res -= mul * cn[h];
      else
        res += mul * cn[h];
    }
    if (mul == 1) add(x, mul);
    was[x] = !was[x];
    cout << res << endl;
  }
  return 0;
}
