#include <bits/stdc++.h>
using namespace std;
template <class P, class Q>
inline P smin(P &a, Q b) {
  if (b < a) a = b;
  return a;
}
template <class P, class Q>
inline P smax(P &a, Q b) {
  if (a < b) a = b;
  return a;
}
const long long N = 5e5 + 6;
long long read() {
  long long x;
  cin >> x;
  return x;
}
long long z[N], cnt[N], a[N], mark[N];
vector<long long> dv[N];
long long c2(long long x) { return x * (x - 1) / 2; }
int32_t main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  z[1] = 1;
  for (long long i = 1; i < N; ++i)
    for (long long j = i; j < N; j += i) {
      if (j != i) z[j] -= z[i];
      dv[j].push_back(i);
    }
  long long n = read(), q = read();
  for (long long i = 0, _n = (long long)(n); i < _n; i++) {
    cin >> a[i];
  }
  long long res = 0;
  while (q--) {
    long long ind = read() - 1;
    long long p = 1 - 2 * mark[ind];
    mark[ind] ^= 1;
    for (long long x : dv[a[ind]]) {
      long long dif = -c2(cnt[x]);
      cnt[x] += p;
      dif += c2(cnt[x]);
      res += dif * z[x];
    }
    cout << res << '\n';
  }
}
