#include <bits/stdc++.h>
using namespace std;
#define MAX 100000
int factors[MAX+5];
int primeFactor[MAX+5];
void sieve()
{
int i, j;
primeFactor[1] = 1;
primeFactor[2] = 2;
for (i = 4; i <= MAX; i+=2)
primeFactor[i] = 2;
for (j = 3; j <= MAX; j+=2)
{
if (primeFactor[j] == 0)
{
primeFactor[j] = j;
for (i = j*j; i <= MAX; i+=j)
{
if (primeFactor[i] == 0)
{
primeFactor[i] = j;
}
}
}
}
}
int main()
{
#ifdef VSP4
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // VSP4
int N, Q, i, j, k, x, ans, last, count;
sieve();
cin >> N;
for (i = 0; i < N; i++)
{
cin >> x;
while (x != 1)
{
factors[primeFactor[x]]++;
x /= primeFactor[x];
}
}
cin >> Q;
for (i = 0; i < Q; i++)
{
cin >> x;
ans = 1e9;
map<int, int> tempMap;
while (x != 1)
{
tempMap[primeFactor[x]]++;
x /= primeFactor[x];
}
for (auto it: tempMap)
{
ans = min(ans, factors[it.first]/it.second);
}
cout << ans << "\n";
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgojZGVmaW5lIE1BWCAxMDAwMDAKCmludCBmYWN0b3JzW01BWCs1XTsKaW50IHByaW1lRmFjdG9yW01BWCs1XTsKCnZvaWQgc2lldmUoKQp7CglpbnQgaSwgajsKCglwcmltZUZhY3RvclsxXSA9IDE7CgoJcHJpbWVGYWN0b3JbMl0gPSAyOwoJZm9yIChpID0gNDsgaSA8PSBNQVg7IGkrPTIpCgkJcHJpbWVGYWN0b3JbaV0gPSAyOwoKCWZvciAoaiA9IDM7IGogPD0gTUFYOyBqKz0yKQoJewoJCWlmIChwcmltZUZhY3RvcltqXSA9PSAwKQoJCXsKCQkJcHJpbWVGYWN0b3Jbal0gPSBqOwoJCQlmb3IgKGkgPSBqKmo7IGkgPD0gTUFYOyBpKz1qKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBpZiAocHJpbWVGYWN0b3JbaV0gPT0gMCkKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBwcmltZUZhY3RvcltpXSA9IGo7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KCQl9Cgl9Cgp9CgppbnQgbWFpbigpCnsKICAgICNpZmRlZiBWU1A0CiAgICBmcmVvcGVuKCJpbnB1dC50eHQiLCAiciIsIHN0ZGluKTsKICAgIGZyZW9wZW4oIm91dHB1dC50eHQiLCAidyIsIHN0ZG91dCk7CiAgICAjZW5kaWYgLy8gVlNQNAoKICAgIGludCBOLCBRLCBpLCBqLCBrLCB4LCBhbnMsIGxhc3QsIGNvdW50OwoKICAgIHNpZXZlKCk7CgogICAgY2luID4+IE47CgogICAgZm9yIChpID0gMDsgaSA8IE47IGkrKykKICAgIHsKICAgIAljaW4gPj4geDsKICAgIAl3aGlsZSAoeCAhPSAxKQogICAgCXsKICAgIAkJZmFjdG9yc1twcmltZUZhY3Rvclt4XV0rKzsKICAgIAkJeCAvPSBwcmltZUZhY3Rvclt4XTsKICAgIAl9CiAgICB9CgogICAgY2luID4+IFE7CiAgICBmb3IgKGkgPSAwOyBpIDwgUTsgaSsrKQogICAgewogICAgCWNpbiA+PiB4OwogICAgCWFucyA9IDFlOTsKICAgIAltYXA8aW50LCBpbnQ+IHRlbXBNYXA7CiAgICAJd2hpbGUgKHggIT0gMSkKICAgICAgICB7CiAgICAgICAgICAgIHRlbXBNYXBbcHJpbWVGYWN0b3JbeF1dKys7CiAgICAJCXggLz0gcHJpbWVGYWN0b3JbeF07CiAgICAgICAgfQogICAgICAgIGZvciAoYXV0byBpdDogdGVtcE1hcCkKICAgICAgICB7CiAgICAgICAgICAgIGFucyA9IG1pbihhbnMsIGZhY3RvcnNbaXQuZmlyc3RdL2l0LnNlY29uZCk7CiAgICAgICAgfQogICAgCWNvdXQgPDwgYW5zIDw8ICJcbiI7CiAgICB9CgogICAgcmV0dXJuIDA7Cn0K