#include <bits/stdc++.h>
#pragma warning(disable : 4996)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("-ffloat-store")
using namespace std;
clock_t time_p = clock();
void aryanc403() {
  time_p = clock() - time_p;
  cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}
const long long int INF = 0xFFFFFFFFFFFFFFFL;
long long int seed;
mt19937 rng(seed = chrono::steady_clock::now().time_since_epoch().count());
inline long long int rnd(long long int l = 0, long long int r = INF) {
  return uniform_int_distribution<long long int>(l, r)(rng);
}
class CMP {
 public:
  bool operator()(pair<long long int, long long int> a,
                  pair<long long int, long long int> b) {
    return !(a.first < b.first || a.first == b.first && a.second <= b.second);
  }
};
void add(map<long long int, long long int> &m, long long int x,
         long long int cnt = 1) {
  auto jt = m.find(x);
  if (jt == m.end())
    m.insert({x, cnt});
  else
    jt->second += cnt;
}
void del(map<long long int, long long int> &m, long long int x,
         long long int cnt = 1) {
  auto jt = m.find(x);
  if (jt->second <= cnt)
    m.erase(jt);
  else
    jt->second -= cnt;
}
bool cmp(const pair<long long int, long long int> &a,
         const pair<long long int, long long int> &b) {
  return a.first < b.first || (a.first == b.first && a.second < b.second);
}
const long long int mod = 1000000007L;
const long long int maxN = 500000L;
long long int T, n, i, j, k, in, cnt, l, r, u, v, x, y, q, no[maxN + 5];
long long int m;
string s;
vector<long long int> f[maxN + 5];
bool vis[maxN + 5];
vector<long long int> a;
void pre(long long int n) {
  for (long long int i = 2; i <= n; ++i) {
    if (!f[i].empty()) continue;
    for (long long int j = i; j <= n; j += i) f[j].push_back(i);
  }
}
long long int count(long long int x) {
  long long int n = (long long int)f[x].size();
  long long int cnt = 0, lim = 1LL << n, i, j, p, v;
  for (i = 0; i < lim; ++i) {
    p = 1;
    v = 0;
    for (j = 0; j < n; ++j)
      if (i & (1LL << j)) {
        p *= f[x][j];
        v++;
      }
    if (v % 2)
      cnt -= no[p];
    else
      cnt += no[p];
  };
  return cnt;
}
void add(long long int x, long long int c) {
  long long int n = (long long int)f[x].size();
  long long int lim = 1LL << n;
  ;
  vector<long long int> a;
  a.clear();
  for (long long int i = 0; i < lim; ++i) {
    long long int p = 1;
    for (long long int j = 0; j < n; ++j)
      if (i & (1LL << j)) p *= f[x][j];
    no[p] += c;
    a.push_back(p);
  };
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  {
    pre(maxN);
    cin >> n >> q;
    a.clear();
    a.reserve(n);
    a.push_back(0);
    for (i = 0; i < (n); ++i) {
      cin >> in;
      a.push_back(in);
    }
    while (q--) {
      cin >> x;
      if (vis[x]) {
        add(a[x], -1);
        vis[x] = false;
        cnt -= count(a[x]);
      } else {
        cnt += count(a[x]);
        vis[x] = true;
        add(a[x], 1);
      };
      cout << cnt << "\n";
    }
  }
  aryanc403();
  return 0;
}
