import java.io.*;
import java.util.Locale;
import java.util.StringTokenizer;
public class TaskC {
private final InputReader reader;
private final OutputWriter writer;
public TaskC(InputReader reader, OutputWriter writer) {
this.reader = reader;
this.writer = writer;
}
public static void main
(String[] args
) { InputReader reader
= new InputReader
(System.
in); OutputWriter writer
= new OutputWriter
(System.
out); new TaskC(reader, writer).run();
writer.writer.flush();
}
final int M = 500 * 1000;
int[][] factors;
int[] cnt = new int[M];
long ans = 0;
int[] in = new int[M];
void add(int x, int mul) {
for (int f : factors[x]) {
int g = (f < 0) ? -f : f;
int h = (f < 0) ? -1 : 1;
if (mul == 1) {
ans += mul * h * cnt[g];
cnt[g] += mul;
} else {
cnt[g] += mul;
ans += mul * h * cnt[g];
}
}
}
public void run() {
factors = new int[M + 1][];
for (int x = 1; x <= M; x++) {
int[] f = new int[6];
int fpt = 0;
int y = x;
for (int i = 2; i * i <= y; i++)
if (y % i == 0) {
if (fpt == 6)
throw new AssertionError();
f[fpt++] = i;
while (y % i == 0)
y /= i;
}
if (y != 1) {
if (fpt == 6)
throw new AssertionError();
f[fpt++] = y;
}
factors[x] = new int[1 << fpt];
for (int msk = 0; msk < (1 << fpt); msk++) {
factors
[x
][msk
] = (1 - (Integer.
bitCount(msk
) % 2) * 2); for (int j = 0; j < fpt; j++)
if (((msk >> j) & 1) == 1)
factors[x][msk] *= f[j];
}
}
int n = reader.nextInt();
int[] A = new int[n];
int q = reader.nextInt();
for (int i = 0; i < n; i++)
A[i] = reader.nextInt();
for (int i = 0; i < q; i++) {
int j = reader.nextInt() - 1;
add(A[j], 1 - 2 * in[j]);
in[j] = 1 - in[j];
writer.printf("%d\n", ans);
}
}
static class InputReader {
tokenizer = null;
}
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
}
}
return tokenizer.nextToken();
}
public int nextInt() {
}
public double nextDouble() {
return Double.
parseDouble(next
()); }
public long nextLong() {
return Long.
parseLong(next
()); }
}
static class OutputWriter {
}
}
}
}