#include <bits/stdc++.h>
using namespace std;
int n, q, x;
long long res, diff;
vector<int> a, pr, shelf, num;
int mn = 500001;
void fill();
void factor(int m, vector<int>& v, vector<int>& w);
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> q;
  a.resize(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  fill();
  for (int i = 0; i < q; ++i) {
    diff = 0;
    vector<int> d, s;
    cin >> x;
    --x;
    factor(a[x], d, s);
    if (shelf[x]) {
      for (int j = 0; j < d.size(); ++j) --num[d[j]];
      for (int j = 0; j < d.size(); ++j) diff += (s[j] * num[d[j]]);
    } else {
      for (int j = 0; j < d.size(); ++j) diff += (s[j] * num[d[j]]);
      for (int j = 0; j < d.size(); ++j) ++num[d[j]];
    }
    res += (shelf[x] ? -diff : diff);
    shelf[x] ^= 1;
    cout << res << endl;
  }
  return 0;
}
void put(int m, vector<int>& v, vector<int>& w) {
  int k = (int)v.size();
  for (int j = 0; j < k; ++j) {
    v.push_back(v[j] * m);
    w.push_back(-w[j]);
  }
}
void factor(int m, vector<int>& v, vector<int>& w) {
  v.assign(1, 1);
  w.assign(1, 1);
  for (int i = 0; pr[i] * pr[i] <= m; ++i)
    if (m % pr[i] == 0) {
      put(pr[i], v, w);
      while (m % pr[i] == 0) m /= pr[i];
    }
  if (m > 1) put(m, v, w);
}
void fill() {
  pr.push_back(2);
  for (int i = 3; i < mn; ++i) {
    bool fl = 1;
    for (int j = 0; fl && pr[j] * pr[j] <= i; ++j) fl = (i % pr[j] > 0);
    if (fl) pr.push_back(i);
  }
  res = 0;
  shelf.assign(n, 0);
  num.assign(mn, 0);
}
