#include <bits/stdc++.h>
using namespace std;
const int N = 2 * 1e5 + 10;
const int M = 5 * 1e5 + 10;
int n, q;
int a[N];
int mu[501000], cnt[M];
long long c[N];
bool v[501000];
bool vis[N];
vector<int> fac[501000];
int main() {
  scanf("%d %d", &n, &q);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), v[a[i]] = true;
  mu[1] = 1;
  for (int i = 1; i <= 500000; i++) {
    for (int j = i + i; j <= 500000; j += i) mu[j] -= mu[i];
  }
  for (int i = 0; i <= N; i++) c[i] = (long long)i * (i - 1) / 2;
  for (int i = 1; i <= 500000; i++) {
    for (int j = i; j <= 500000; j += i) {
      if (mu[i] != 0 && v[j]) fac[j].push_back(i);
    }
  }
  long long ans = 0;
  for (int i = 1; i <= q; i++) {
    int x;
    scanf("%d", &x);
    if (vis[x] == 0) {
      vis[x] = 1;
      for (int j = 0; j < fac[a[x]].size(); j++) {
        int y = fac[a[x]][j];
        ans += mu[y] * (cnt[y]++);
      }
    } else {
      vis[x] = 0;
      for (int j = 0; j < fac[a[x]].size(); j++) {
        int y = fac[a[x]][j];
        ans -= mu[y] * (--cnt[y]);
      }
    }
    printf("%I64d\n", ans);
  }
}
