#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-10;
const bool debug = 0;
//---------------------------------//
int n, m;
map<int, ll> mm;
int a[112345];
int db[30][112345];
ll gcd(ll a, ll b) {
if (b == 0) return a;
return gcd(b, a % b);
}
// [l,r)
int rangegcd(int l, int r) {
int res = a[l];
int d = r - l;
REP(i, 20) if (d >> i & 1) {
res = gcd(res, db[i][l]);
l += 1<<i;
}
return res;
}
int main() {
cin >> n >> m;
REP(i, n) scanf("%d", a + i);
REP(i, n) db[0][i] = a[i];
REP(i, 20) REP(j, n) {
if (j + (1<<i) >= n) break;
db[i + 1][j] = gcd(db[i][j], db[i][j + (1<<i)]);
}
REP(l, n) {
int r = l; // [l,r]
int g = a[l];
while (r < n) {
int lb = r, ub = n + 1;
while (ub - lb > 1) {
int m = (lb + ub) / 2;
if (rangegcd(l, m) == g) lb = m;
else ub = m;
}
mm[g] += lb - r;
r = lb;
if (r < n) g = gcd(g, a[r]);
}
}
REP(i, m) {
int x;
scanf("%d", &x);
printf("%lld\n", mm[x]);
}
return 0;
}
./Main.cpp: In function ‘int main()’:
./Main.cpp:44:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
REP(i, n) scanf("%d", a + i);
^
./Main.cpp:74:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &x);
^