#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const long long infLL = 9000000000000000000;
inline bool checkBit(long long n, int i) { return n & (1LL << i); }
inline long long setBit(long long n, int i) {
  return n | (1LL << i);
  ;
}
inline long long resetBit(long long n, int i) { return n & (~(1LL << i)); }
int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
inline bool isLeapYear(long long year) {
  return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);
}
inline void normal(long long &a) {
  a %= 1000000007;
  (a < 0) && (a += 1000000007);
}
inline long long modMul(long long a, long long b) {
  a %= 1000000007, b %= 1000000007;
  normal(a), normal(b);
  return (a * b) % 1000000007;
}
inline long long modAdd(long long a, long long b) {
  a %= 1000000007, b %= 1000000007;
  normal(a), normal(b);
  return (a + b) % 1000000007;
}
inline long long modSub(long long a, long long b) {
  a %= 1000000007, b %= 1000000007;
  normal(a), normal(b);
  a -= b;
  normal(a);
  return a;
}
inline long long modPow(long long b, long long p) {
  long long r = 1;
  while (p) {
    if (p & 1) r = modMul(r, b);
    b = modMul(b, b);
    p >>= 1;
  }
  return r;
}
inline long long modInverse(long long a) { return modPow(a, 1000000007 - 2); }
inline long long modDiv(long long a, long long b) {
  return modMul(a, modInverse(b));
}
const int maxn = 5e5 + 100;
int fp[maxn], a[maxn >> 1], vis[maxn >> 1], cnt[maxn];
long long ans;
vector<int> factorise(int num) {
  vector<int> ret;
  while (num > 1) {
    ret.emplace_back(fp[num]);
    num /= fp[num];
  }
  sort(ret.begin(), ret.end());
  ret.erase(unique(ret.begin(), ret.end()), ret.end());
  return ret;
}
void add(int idx) {
  vector<int> store = factorise(a[idx]);
  for (int i = 1; i < (1 << store.size()); ++i) {
    int num = 1;
    for (int j = 0; j < store.size(); ++j) {
      if (checkBit(i, j)) num *= store[j];
    }
    if (__builtin_popcount(i) & 1)
      ans += cnt[num];
    else
      ans -= cnt[num];
    ++cnt[num];
  }
}
void del(int idx) {
  vector<int> store = factorise(a[idx]);
  for (int i = 1; i < (1 << store.size()); ++i) {
    int num = 1;
    for (int j = 0; j < store.size(); ++j) {
      if (checkBit(i, j)) num *= store[j];
    }
    --cnt[num];
    if (__builtin_popcount(i) & 1)
      ans -= cnt[num];
    else
      ans += cnt[num];
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  for (int i = 0; i < maxn; ++i) fp[i] = i;
  for (int i = 2; i * i <= maxn; ++i) {
    for (int j = i; j <= maxn; j += i) fp[j] = min(fp[j], i);
  }
  int n, q, exist = 0;
  cin >> n >> q;
  for (int i = 0; i < n; ++i) cin >> a[i];
  while (q--) {
    int num;
    cin >> num;
    --num;
    if (vis[num])
      del(num), vis[num] = 0, --exist;
    else
      add(num), vis[num] = 1, ++exist;
    cout << ((long long)(exist) * (exist - 1)) / 2 - ans << '\n';
  }
  return 0;
}
