#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;
const int maxn5 = 2e5 + 10;
const int maxnt = 1.2e6 + 10;
const int maxn3 = 1e3 + 10;
const long long mod = 1e9 + 7;
const long long inf = 2e18;
bool np[maxn], mark[maxn5];
vector<int> pri[maxn];
int adade[maxn5][70], val[maxn5][70], cnt[maxn], a[maxn5];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  for (int i = 2; i < maxn; i++)
    if (!np[i])
      for (int j = i; j < maxn; j += i) {
        pri[j].push_back(i);
        np[j] = true;
      }
  int n, q;
  cin >> n >> q;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    for (int mask = 1; mask < (1 << int(pri[a[i]].size())); mask++) {
      adade[i][mask] = 1;
      int cnt = 0;
      for (int j = 0; j < int(pri[a[i]].size()); j++)
        if ((mask >> j) & 1) adade[i][mask] *= pri[a[i]][j], cnt++;
      if (cnt % 2 == 0)
        val[i][mask] = -1;
      else
        val[i][mask] = 1;
    }
  }
  long long sz = 0;
  for (int i = 0; i < q; i++) {
    int b;
    cin >> b;
    b--;
    if (mark[b])
      for (int mask = 1; mask < (1 << int(pri[a[b]].size())); mask++)
        cnt[adade[b][mask]]--;
    if (mark[b]) sz--;
    long long now = 0;
    for (int mask = 1; mask < (1 << int(pri[a[b]].size())); mask++)
      now += cnt[adade[b][mask]] * val[b][mask];
    ans += (mark[b] ? -1 : 1) * (sz - now);
    if (!mark[b])
      for (int mask = 1; mask < (1 << int(pri[a[b]].size())); mask++)
        cnt[adade[b][mask]]++;
    if (!mark[b]) sz++;
    mark[b] ^= true;
    cout << ans << '\n';
  }
  return 0;
}
