#include <bits/stdc++.h>
using namespace std;
int n, q, cnt = 0;
long long ans = 0;
bool vis[200000];
vector<int> f[200000];
map<vector<int>, int> mp[6];
inline void ins(const vector<int> &v) {
  int k = v.size();
  int sign = ((k & 1) ? -1 : 1);
  ans += sign * mp[k - 1][v];
  mp[k - 1][v]++;
}
inline void remove(const vector<int> &v) {
  int k = v.size();
  int sign = ((k & 1) ? -1 : 1);
  mp[k - 1][v]--;
  ans -= sign * mp[k - 1][v];
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> q;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    for (int j = 2; j * j <= a; ++j) {
      if (a % j) continue;
      f[i].push_back(j);
      while (a % j == 0) a /= j;
    }
    if (a > 1) f[i].push_back(a);
    assert(f[i].size() <= 6);
  }
  while (q--) {
    int ind;
    cin >> ind, --ind;
    if (!vis[ind])
      ans += cnt++;
    else
      ans -= --cnt;
    for (int i = 1; i < (1 << (int)f[ind].size()); ++i) {
      vector<int> v;
      for (int j = 0; j < f[ind].size(); ++j)
        if (i & (1 << j)) v.push_back(f[ind][j]);
      if (!vis[ind])
        ins(v);
      else
        remove(v);
    }
    vis[ind] ^= 1;
    cout << ans << '\n';
  }
  return 0;
}
