#include <bits/stdc++.h>
using namespace std;
const int nmax = 200005;
const int N = 500005;
const long long mod = 1e9 + 7;
const long long inf = 1e9;
const long double EPS = 1e-18;
const long double PI = acos(-1.0);
const int kor = 320;
long long cnt[N];
long long a[nmax];
int used[nmax];
int lp[N];
int dp[N];
vector<int> pr;
long long ans;
void add(long long first, int d) {
  vector<int> p;
  while (first > 1) {
    int c = lp[first];
    p.push_back(c);
    while (first % c == 0) first /= c;
  }
  int n = p.size();
  for (int i = 0; i < (1 << n); ++i) {
    if (!i)
      dp[i] = 1;
    else {
      int b = __builtin_ctz(i);
      dp[i] = p[b] * dp[i ^ (1 << b)];
    }
    if (d == -1) cnt[dp[i]]--;
    int b = __builtin_popcount(i);
    if (b % 2)
      ans -= cnt[dp[i]] * 1ll * d;
    else
      ans += cnt[dp[i]] * 1ll * d;
    if (d == 1) cnt[dp[i]]++;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  for (int i = 2; i < N; ++i) {
    if (!lp[i]) {
      lp[i] = i;
      pr.push_back(i);
    }
    for (int j = 0; j < pr.size() && pr[j] <= lp[i] && i * pr[j] < N; j++) {
      lp[i * pr[j]] = pr[j];
    }
  }
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> a[i];
  while (m--) {
    int first;
    cin >> first;
    first--;
    long long c = a[first];
    if (!used[first])
      add(c, 1);
    else
      add(c, -1);
    used[first] ^= 1;
    cout << ans << '\n';
  }
  return 0;
}
