比赛 4043级NOIP2022欢乐赛3rd 评测结果 AAAATTTTTT
题目名称 GCD和LCM问题 最终得分 40
用户昵称 yrtiop 运行时间 19.094 s
代码语言 C++ 内存使用 5.20 MiB
提交时间 2022-11-04 20:51:33
显示代码纯文本
#include <bits/stdc++.h>

const int maxn = 1e5 + 5;
int n,Q;
unsigned a[maxn],b[maxn];

unsigned gcd(unsigned x,unsigned y) {
	return y ? gcd(y , x % y) : x;
}

int main() {
	freopen("gcdlcm.in","r",stdin);
	freopen("gcdlcm.out","w",stdout);
	scanf("%d %d",&n,&Q);
	for(int i = 1;i <= n;++ i)
		scanf("%u",&a[i]);
	for(int i = 1;i <= n;++ i)
		scanf("%u",&b[i]);
	while(Q --) {
		int op,l,r,k;
		scanf("%d %d %d",&op,&l,&r);
		if(op == 1) {
			scanf("%d",&k);
			for(int i = l;i <= r;++ i)
				a[i] = k;
		}
		else {
			unsigned ans = 3e9;
			for(int i = l;i <= r;++ i) {
				unsigned t = gcd(a[i] , b[i]);
				ans = std::min(ans , a[i] / t * b[i] / t);
			}
			printf("%u\n",ans);
		}
	}
	return 0;
}