#include <bits/stdc++.h>
using namespace std;
int a[200005], h[200005], c[500005], m[500005], n, q, x, o;
vector<int> v[500005];
long long r;
int main() {
  m[1] = 1;
  for (int i = 1; i <= 500000; i++) {
    for (int j = i; j <= 500000; j += i) v[j].push_back(i);
    if (v[i].size() == 2)
      for (int j = i; j <= 500000; j += i)
        m[j] = j / i % i == 0 ? 0 : -m[j / i];
  }
  cin >> n >> q;
  for (int k = 0; k < n; k++) cin >> a[k];
  for (int i = 0; i < q; i++) {
    cin >> x;
    x--;
    for (int j = 0; j < v[a[x]].size(); j++) {
      int d = v[a[x]][j];
      c[d] -= h[x];
      r += (h[x] ? -1 : 1) * m[d] * (2 * c[d] + 1);
      c[d] += !h[x];
    }
    if (a[x] == 1) o += h[x] ? -1 : 1;
    h[x] ^= 1;
    cout << (r - o) / 2 << '\n';
  }
  return 0;
}
