#include <bits/stdc++.h>
using namespace std;
void print_vector(vector<int> v);
void print_array(int* array, int start, int end);
int n, q;
int cnt[500100], a[200100], in[500100], x;
vector<int> p[500100];
long long ans = 0;
long long add(int x, int sign) {
  for (int mask = 0; mask < (1 << (int)(p[x]).size()); mask++) {
    int pr = 1;
    for (int j = (0), _b = ((int)(p[x]).size()); j < _b; j++) {
      if ((mask & (1 << j)) != 0) pr *= p[x][j];
    }
    if (sign > 0) {
      ans += (long long)((1 + (__builtin_popcount(mask) & 1) * (-2)) * cnt[pr] *
                         sign);
      cnt[pr] += (long long)sign;
    } else {
      cnt[pr] += (long long)sign;
      ans += (long long)((1 + (__builtin_popcount(mask) & 1) * (-2)) * cnt[pr] *
                         sign);
    }
  }
  return ans;
}
int main() {
  for (int i = (2), _b = (500000); i < _b; i++) {
    if (p[i].empty()) {
      for (int j = i; j <= 500000; j += i) {
        p[j].push_back(i);
      }
    }
  }
  scanf("%d", &n), scanf("%d", &q);
  for (int i = (0), _b = (n); i < _b; i++) scanf("%d", &a[i]);
  for (int i = (0), _b = (500010); i < _b; i++) in[i] = 1;
  memset(cnt, 0, sizeof cnt);
  for (int i = (0), _b = (q); i < _b; i++) {
    scanf("%d", &x);
    x--;
    cout << add(a[x], in[x]) << endl;
    in[x] *= -1;
  }
  return 0;
}
void print_array(int* array, int start, int end) {
  printf("[");
  for (int i = (start), _b = (end); i < _b; i++) {
    printf("%d ", array[i]);
  }
  printf("]");
  printf("\n");
}
void print_vector(vector<int> v) {
  printf("[");
  for (int i = (0), _b = (v.size()); i < _b; i++) {
    printf("%d ", v[i]);
  }
  printf("]");
  printf("\n");
}
