#include <bits/stdc++.h>
using namespace std;
int a[500005];
vector<int> p[500005];
long long ans;
int has[500005];
int mal[500005];
int cnt[500005];
void solve(int x, int sign) {
  for (int i = 0; i < (1 << p[x].size()); i++) {
    if (i == 0)
      mal[i] = 1;
    else
      mal[i] = mal[i & (i - 1)] * p[x][__builtin_ctz(i)];
    if (sign < 0) cnt[mal[i]]--;
    if (__builtin_popcount(i) & 1)
      ans -= cnt[mal[i]] * sign;
    else
      ans += cnt[mal[i]] * sign;
    if (sign > 0) cnt[mal[i]]++;
  }
}
int main() {
  int n, q;
  for (int i = 2; i < 500005; i++)
    if (p[i].empty())
      for (int j = i; j < 500005; j += i) p[j].push_back(i);
  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    has[i] = 1;
  }
  int x;
  while (q--) {
    cin >> x;
    x--;
    solve(a[x], has[x]);
    has[x] *= -1;
    cout << ans << endl;
  }
  return 0;
}
