#include <algorithm>
#include <cmath>
#include <iostream>
#define int long long
const int N = 1e6 + 10;
int tree[N << 2], a[N];
inline int read() {
int ans = 0, flag = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
flag = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
ans = ans * 10 + c - '0';
c = getchar();
}
return ans * flag;
}
void pushup(int p) { tree[p] = std::__gcd(tree[p << 1], tree[p << 1 | 1]); }
void build(int p, int l, int r) {
if (l == r) {
tree[p] = a[l];
return;
}
int mid = (l + r) >> 1;
build(p << 1, l, mid);
build(p << 1 | 1, mid + 1, r);
pushup(p);
}
int query(int p, int l, int r, int a, int b) {
if (l > b || r < a) {
return 0;
}
if (a <= l && r <= b) {
return tree[p];
}
int mid = (l + r) >> 1;
return std::__gcd(query(p << 1, l, mid, a, b), query(p << 1 | 1, mid + 1, r, a, b));
}
int n, q;
signed main() {
n = read();
for (int i = 1; i <= n; ++i) {
a[i] = read();
}
build(1, 1, n);
q = read();
for (int i = 1; i <= q; ++i) {
int l = read(), r = read();
printf("%lld\n", query(1, 1, n, l, r) % 11);
}
return 0;
}
9021-02
最新推荐文章于 2024-08-29 16:57:08 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)