#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
int b[500005], f[500005], n, q, g[500005], r[200005];
long long ans;
vector<int> v[500005];
int main() {
  int O = 0;
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) scanf("%d", r + i);
  g[1] = 1;
  for (int i = 1; i <= 500000; i++) {
    v[i].push_back(i);
    for (int j = i * 2; j <= 500000; j += i) v[j].push_back(i), g[j] -= g[i];
  }
  while (q--) {
    int x, y;
    scanf("%d", &y);
    x = r[y];
    if (b[y]) {
      b[y] = 0;
      for (int i = 0; i < v[x].size(); i++) ans -= (--f[v[x][i]]) * g[v[x][i]];
    } else {
      b[y] = 1;
      for (int i = 0; i < v[x].size(); i++) ans += (f[v[x][i]]++) * g[v[x][i]];
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
