3131

☀️☃️☃️☃️☀️  •  10天前


``#include

include

using namespace std; long long st[100001][18]; long long getGcd(long long x, long long y) {

while (x % y) {
	long long t = x % y;
	x = y;
	y = t;
}
return y;

} int main() {

int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> st[i][0];
for (int j = 1; j < log2(n); j++) {
	for (int i = 1; i + (1 << j) - 1 <= n; i++) {
		st[i][j] = st[i][j - 1] 
			/ getGcd(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]) 
			* st[i + (1 << (j - 1))][j - 1] ;
	}
}
for (int i = 1; i <= m; i++) {
	int l, r;
	cin >> l >> r;
	int x = log2(r - l + 1);
	cout << st[l][x] / getGcd(st[l][x], st[r - (1 << x) + 1][x])
		* st[r - (1 << x) + 1][x] << endl;
}
return 0;

}``


评论:

请先登录,才能进行评论