-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path475D.cpp
More file actions
executable file
·48 lines (39 loc) · 940 Bytes
/
Copy path475D.cpp
File metadata and controls
executable file
·48 lines (39 loc) · 940 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <map>
#include <vector>
using namespace std;
vector<int> readVector(int n) {
vector<int> res(n);
for (int i = 0; i < n; i++) cin >> res[i];
return res;
}
int gcd(int a, int b) {
while (b) {
int temp = b;
b = a % b;
a = temp;
}
return a;
}
int main() {
ios_base::sync_with_stdio(false);
int n; cin >> n;
vector<int> v = readVector(n);
map<int, long long> results;
map<int, int> divisors;
for (int i = 0; i < n; i++) {
map<int, int> nextDivisors;
for (const auto &p : divisors) {
nextDivisors[gcd(p.first, v[i])] += p.second;
}
nextDivisors[v[i]]++;
for (const auto &p : nextDivisors)
results[p.first] += p.second;
divisors = move(nextDivisors);
}
int q; cin >> q;
while (q--) {
int x; cin >> x;
cout << results[x] << endl;
}
}