__gcd题解

麦睿生  •  28天前


#include<bits/stdc++.h>
using namespace std;
long long n,i,a[10005],ans1,b[10005];
int main()
{
	scanf("%lld",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		b[i]=a[i];
	}
	for(i=1;i<=(n-1);i++)
	{
		a[i+1]=__gcd(a[i],a[i+1]);
		b[i+1]=(b[i]*b[i+1])/(__gcd(b[i],b[i+1]));
	}
	printf("%lld %lld",a[n],b[n]);
    return 0;
}

水题


Comments: