#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 2e5 + 10, MAX = 5e5 + 10;
bitset<MAXN> exist;
bitset<MAX> b;
long long a[MAXN], cnt[MAX], ans;
vector<long long> prime[MAX];
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  for (long long i = 2; i < MAX; ++i)
    if (!b[i])
      for (long long j = i; j < MAX; j += i) {
        prime[j].push_back(i);
        b[j] = true;
      }
  long long n, q, a1;
  cin >> n >> q;
  for (long long i = 0; i < n; ++i) cin >> a[i];
  while (q--) {
    cin >> a1;
    --a1;
    long long res = 0;
    long long s = prime[a[a1]].size();
    long long t = 1 << s;
    if (exist[a1])
      for (long long mask = 0; mask < t; ++mask) {
        long long now = 1;
        for (long long i = 0; i < s; ++i)
          if (mask & (1 << i)) now *= prime[a[a1]][i];
        --cnt[now];
      }
    for (long long mask = 0; mask < t; ++mask) {
      long long now = 1;
      for (long long i = 0; i < s; ++i)
        if (mask & (1 << i)) now *= prime[a[a1]][i];
      if (__builtin_popcount(mask) & 1)
        res -= cnt[now];
      else
        res += cnt[now];
    }
    if (!exist[a1]) {
      for (long long mask = 0; mask < t; ++mask) {
        long long now = 1;
        for (long long i = 0; i < s; ++i)
          if (mask & (1 << i)) now *= prime[a[a1]][i];
        ++cnt[now];
      }
    }
    ans += res * (exist[a1] ? -1 : 1);
    exist[a1] = 1 - exist[a1];
    cout << ans << '\n';
  }
  return 0;
}
