#include <bits/stdc++.h>
using namespace std;
const int maxn = 500005;
int n, q, cur, num, p, x;
int a[maxn], cnt[maxn];
bool now[maxn];
int main() {
  scanf("%d%d", &n, &q);
  for (int(i) = 1; (i) <= n; i++) scanf("%d", &a[i]);
  while (q--) {
    scanf("%d", &p);
    x = a[p];
    vector<int> prime;
    for (int i = 2; i * i <= x; i++)
      if (x % i == 0) {
        prime.push_back(i);
        while (x % i == 0) x /= i;
      }
    if (x > 1) prime.push_back(x);
    if (!now[p]) {
      now[p] = true;
      num++;
      int ch = 0;
      for (int mask = 1; mask < (1 << prime.size()); mask++) {
        int bit = 0, mult = 1;
        for (int j = 0; j < prime.size(); j++)
          if (mask & (1 << j)) {
            bit++;
            mult *= prime[j];
          }
        if (bit & 1)
          ch += cnt[mult];
        else
          ch -= cnt[mult];
        cnt[mult]++;
      }
      cur += ch;
      printf("%I64d\n", (long long)num * (num - 1) / 2 - cur);
    } else {
      now[p] = false;
      num--;
      int ch = 0;
      for (int mask = 1; mask < (1 << prime.size()); mask++) {
        int bit = 0, mult = 1;
        for (int j = 0; j < prime.size(); j++)
          if (mask & (1 << j)) {
            bit++;
            mult *= prime[j];
          }
        cnt[mult]--;
        if (bit & 1)
          ch += cnt[mult];
        else
          ch -= cnt[mult];
      }
      cur -= ch;
      printf("%I64d\n", (long long)num * (num - 1) / 2 - cur);
    }
  }
  return 0;
}
