比赛 |
4043级NOIP2022欢乐赛3rd |
评测结果 |
AAAATTTTTT |
题目名称 |
GCD和LCM问题 |
最终得分 |
40 |
用户昵称 |
op_组撒头屯 |
运行时间 |
19.115 s |
代码语言 |
C++ |
内存使用 |
4.28 MiB |
提交时间 |
2022-11-04 21:54:21 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
const int N=50000+5;
typedef long long ll;
const ll inf=0x3f3f3f3f3f3f;
int n,q;
int a[N],b[N];
int gcd(int x,int y){
if (y==0)return x;
return gcd(y,x%y);
}
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("%d",&a[i]);
}
for (int i=1;i<=n;i++){
scanf("%d",&b[i]);
}
while(q--){
int opt,l,r,k;scanf("%d%d%d",&opt,&l,&r);
if (opt==1){
scanf("%d",&k);
for (int i=l;i<=r;i++)a[i]=k;
}
else{
ll ans=inf;
for (int i=l;i<=r;i++){
ll p=gcd(a[i],b[i]);
ans=min(ans,1ll*a[i]*b[i]/(p*p));
}
printf("%lld\n",ans);
}
}
return 0;
}