#include <bits/stdc++.h>
using namespace std;
const long long LL = 1 << 18, RR = LL * 2 - 1;
const long long INF = 1000000010;
vector<long long> huh[500010];
long long cnt[500010];
bitset<500010> used;
vector<long long> A;
long long col;
long long calc(long long i) {
  long long res = 0;
  for (long long mask = 1; mask < (1 << huh[A[i]].size()); mask++) {
    long long mult = -1, uh = 1;
    for (long long j = 0; j < huh[A[i]].size(); j++) {
      if (mask & (1 << j)) {
        mult *= -1;
        uh *= huh[A[i]][j];
      }
    }
    res += mult * cnt[uh];
    if (used[i])
      cnt[uh]--;
    else
      cnt[uh]++;
  }
  return res;
}
long long ans = 0;
void solve(long long i) {
  if (A[i] == 1) {
    if (used[i])
      ans -= col - 1, col--, used[i] = 0;
    else
      ans += col, col++, used[i] = 1;
    return;
  }
  if (used[i])
    ans -= col - calc(i), col--, used[i] = 0;
  else
    ans += col - calc(i), col++, used[i] = 1;
}
signed main() {
  ios_base::sync_with_stdio(false);
  long long n, q;
  cin >> n >> q;
  A.resize(n);
  for (long long i = 2; i <= 500000; i++) {
    if (huh[i].size()) continue;
    for (long long j = i; j <= 500000; j += i) {
      huh[j].push_back(i);
    }
  }
  for (long long i = 0; i < n; i++) cin >> A[i];
  for (long long i = 0, a; i < q; i++) {
    cin >> a;
    a--;
    solve(a);
    ;
    cout << ans << '\n';
  }
}
