#include using namespace std; #define FOR(i,n) for(int i=0;i<(n);i++) #define all(t) (t).begin(),(t).end() #define MOD 1000000007 typedef long long ll; template inline bool chmax(T& a,T b){if(a inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}} template inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;} template inline T LCM(T a,T b){return a*b/GCD(a,b);} int main(){ ll n,q; ll a[100010],x[100010]; vector v; cin >> n; FOR(i,n){ cin >> a[i]; v.push_back(a[i]); } ll cnt=0; cin >> q; FOR(i,q){ cin >> x[i]; if(x[i]==1){ FOR(j,q-i){ cout << 0 << endl; } return 0; } vector q; ll sum=0; FOR(j,(int)v.size()){ if(v[j]%x[i]==1){ cnt++; }else{ q.push_back(v[j]%x[i]); sum+=v[j]%x[i]; } } v=q; cout << sum+cnt << endl; } }