C. Orac and LCM

194 篇文章 1 订阅
4 篇文章 0 订阅
该博客介绍了如何解决一个计算问题,其中Orac有一个长度为n的序列a,任务是找出所有不同元素对(a_i, a_j)的LCM的GCD。给定1≤a_i≤200000的限制条件,博主提供了输入输出示例,并且指出在特定示例中,计算得到的GCD值。" 136598083,12831281,华为OD机试:求解连续数列的JAVA实现,"['华为od', 'java', '算法', '机试真题']
摘要由CSDN通过智能技术生成

链接:https://codeforces.ml/contest/1350/problem/C

For the multiset of positive integers s={s1,s2,…,sk}s={s1,s2,…,sk}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of ss as follow:

  • gcd(s)gcd(s) is the maximum positive integer xx, such that all integers in ss are divisible on xx.
  • lcm(s)lcm(s) is the minimum positive integer xx, that divisible on all integers from ss.

For example, gcd({8,12})=4,gcd({12,18,6})=6gcd({8,12})=4,gcd({12,18,6})=6 and lcm({4,6})=12lcm({4,6})=12. Note that for any positive integer xx, gcd({x})=lcm({x})=xgcd({x})=lcm({x})=x.

Orac has a sequence aa with length nn. He come up with the multiset t={lcm({ai,aj}) | i<j}t={lcm({ai,aj}) | i<j}, and asked you to find the value of gcd(t)gcd(t) for him. In other words, you need to calculate the GCD of LCMs of all pairs of elements in the given sequence.

Input

The first line contains one integer n (2≤n≤100000)n (2≤n≤100000).

The second line contains nn integers, a1,a2,…,ana1,a2,…,an (1≤ai≤2000001≤ai≤200000).

Output

Print one integer: gcd({lcm({ai,aj}) | i<j})gcd({lcm({ai,aj}) | i<j}).

Examples

input

Copy

2
1 1

output

Copy

1

input

Copy

4
10 24 40 80

output

Copy

40

input

Copy

10
540 648 810 648 720 540 594 864 972 648

output

Copy

54

Note

For the first example, t={lcm({1,1})}={1}t={lcm({1,1})}={1}, so gcd(t)=1gcd(t)=1.

For the second example, t={120,40,80,120,240,80}t={120,40,80,120,240,80}, and it's not hard to see that gcd(t)=40gcd(t)=40.

代码:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<cstdlib>
#include<cmath>
#include<stack>
#include<map>
#include<algorithm>
using namespace std;
#define ll long long
#define lb long double
#define INF 0x3f3f3f3f
#define maxn 200010
ll n,k,l,t,x,s;
ll a[200001];
ll dp[100001];
map<ll,ll>m;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		m[a[i]]++;
	}
	k=1;
	for(ll i=2;i<=200000;i++)
	{
		for(ll j=i+i;j<=200000;j+=i)
		{
			m[i]+=m[j];
		}
		if(m[i]>=n-1)
		{
			k*=i/__gcd(i,k);
		}
	}
	cout<<k;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值