// ~~ icebear love attttt ~~
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
template<class T>
bool minimize(T &a, const T &b) {
if (a > b) return a = b, true;
return false;
}
template<class T>
bool maximize(T &a, const T &b) {
if (a < b) return a = b, true;
return false;
}
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORR(i,a,b) for(int i=(a); i>=(b); --i)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define RED(i, n) for(int i=(n)-1; i>=0; --i)
#define MASK(i) (1LL << (i))
#define BIT(S, i) (((S) >> (i)) & 1)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define task "icebearat"
const int MOD = 1e9 + 7;
const int inf = 1e9 + 27092008;
const ll INF = 1e18 + 27092008;
const int N = 2e5 + 5;
int n, q, a[N], rmq[N][20];
map<int, ll> cnt;
int getGcd(int l, int r) {
int k = __lg(r - l + 1);
return __gcd(rmq[l][k], rmq[r - MASK(k) + 1][k]);
}
void init(void) {
cin >> n;
FOR(i, 1, n) cin >> a[i];
FOR(i, 1, n) rmq[i][0] = a[i];
cin >> q;
}
void process(void) {
FOR(j, 1, 19) FOR(i, 1, n - MASK(j) + 1)
rmq[i][j] = __gcd(rmq[i][j - 1], rmq[i + MASK(j - 1)][j - 1]);
FOR(i, 1, n) {
int l = i;
while(l <= n) {
int low = l, high = n, res = 0, cur = getGcd(i, l);
while(low <= high) {
int mid = (low + high) >> 1;
if (getGcd(i, mid) == cur) res = mid, low = high + 1;
else high = mid - 1;
}
cnt[cur] += res - l + 1;
l = res + 1;
}
}
while(q--) {
int x; cin >> x;
if (cnt.find(x) == cnt.end()) cout << "0\n";
else cout << cnt[x] << '\n';
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int tc = 1;
// cin >> tc;
while(tc--) {
init();
process();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tjdXJdICs9IHJlcyAtIGwgKyAxOwogICAgICAgICAgICBsID0gcmVzICsgMTsKICAgICAgICB9CiAgICB9CgogICAgd2hpbGUocS0tKSB7CiAgICAgICAgaW50IHg7IGNpbiA+PiB4OwogICAgICAgIGlmIChjbnQuZmluZCh4KSA9PSBjbnQuZW5kKCkpIGNvdXQgPDwgIjBcbiI7CiAgICAgICAgZWxzZSBjb3V0IDw8IGNudFt4XSA8PCAnXG4nOwogICAgfQp9CgppbnQgbWFpbigpIHsKICAgIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oMCk7CiAgICBjaW4udGllKDApOyBjb3V0LnRpZSgwKTsKICAgIGlmIChmb3Blbih0YXNrIi5pbnAiLCAiciIpKSB7CiAgICAgICAgZnJlb3Blbih0YXNrIi5pbnAiLCAiciIsIHN0ZGluKTsKICAgICAgICBmcmVvcGVuKHRhc2siLm91dCIsICJ3Iiwgc3Rkb3V0KTsKICAgIH0KICAgIGludCB0YyA9IDE7Ci8vICAgIGNpbiA+PiB0YzsKICAgIHdoaWxlKHRjLS0pIHsKICAgICAgICBpbml0KCk7CiAgICAgICAgcHJvY2VzcygpOwogICAgfQogICAgcmV0dXJuIDA7Cn0KCg==