链接: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;
}

C. Orac and LCM相关推荐

  1. C. Orac and LCM(数论lcm, gcd)

    C. Orac and LCM 思路 题目非常简单,就是求gcd(lcm(i,j))foriinrange(n),forjinrange(n),i<jgcd(lcm_(i,\ j))\ for\ ...

  2. Orac and LCM #641(div2) c题--求质因数次小指数

    Orac and LCM cf地址 For the multiset of positive integers s={s1,s2,-,sk}, define the Greatest Common D ...

  3. Orac and LCM(数论)

    题目链接: Orac and LCM 大致题意: 给你一个长度为 n 的数组,求 gcd {lcm({ai , aj}) | i < j} 解题思路: gcd1=gcd[lcm(a1,a2),l ...

  4. C. Orac and LCM(数论)

    C. Orac and LCM(数论) 题目传送门 g 1 = g c d [ l c m ( a 1 , a 2 ) , l c m ( a 1 , a 3 ) - l c m ( a 1 , a ...

  5. C. Orac and LCM(gcd与lcm的性质)

    Problem - 1350C - Codeforces 题意: 对于正整数的多集合s={s1,s2,...,sk},定义s的最大公除数(GCD)和最小公倍数(LCM)如下. gcd(s)是最大的正整 ...

  6. CodeForces - 1350C Orac and LCM(数论)

    题目链接:点击查看 题目大意:给出 n 个数,先求出两两 lcm 后的集合 t ,再求这个集合 t 的 gcd 题目分析:做这个题得知道一个前置知识:对于 lcm 和 gcd 运算来说,每个质因子都相 ...

  7. 【Codeforces 1349A】Orac and LCM

    思路 gcd1=gcd[lcm(a1,a2),lcm(a1,a3)-lcm(a1,an)]=gcd(a1,lcm(a2,a3-an)) gcd2=gcd[lcm(a2,a3),lcm(a2,a4)-l ...

  8. CF1349A. Orac and LCM(策略 + 维护后缀gcd)

    原题链接 题意:给你n个数,给你两种定义一个为gcd,lcm 如:gcd({8,12}) =4, gcd({12,18,6})=6,lcm({4,6})=12. 1.对于这个n个数我们定义一个集合t= ...

  9. codeforces 1350.Div2 A-D Orac and xxx

    目录 A.Orac and Fac 1:问题描述 2:问题分析: 3:代码: B.Orac and Models 1:问题描述 2:问题分析: 3:代码 C.Orac and LCM 1:问题描述 2 ...

最新文章

  1. 刻意练习:LeetCode实战 -- 二叉树的后序遍历
  2. 图书管理系统前景与范围文档
  3. WebApi接口安全认证——HTTP之摘要认证
  4. linux nohup 终端断了,linux 后台执行nohup 命令,终端断开无影响
  5. 深度学习元老Yann Lecun详解卷积神经网络
  6. 有什么产品工作,可以每天摸胸,还不用冒生命危险?
  7. jenkins组权限_JENKINS针对不同项目组对用户进行权限分配-阿里云开发者社区
  8. 生活 list.php,list.php
  9. Mybatis批量删除
  10. linux 停止jar 指令,Linux编辑启动、停止与重启springboot jar包脚本实例
  11. 普通程序员想转人工智能,不知道它?别想了!
  12. 在windows下安装node-sass失败,提示\node-sass: Command failed,解决方案
  13. Springboot整合SpringSecurity--对静态文件进行权限管理
  14. iol植入手术过程_年龄相关性白内障phaco+Iol植入术的手术配合及体会
  15. 将 libVLC 视频渲染到 QWidget 中
  16. 十大经典排序算法及比较与分析 ( 动画演示 ) ( 可视化工具 )
  17. ORACLE 取唯一数据
  18. gem是什么证书_gem是什么
  19. 计算机监听的端口,侦听计算机的指定端口并分析其数据包,监听,本,解析
  20. 数字平台是未来经济,平台将成为未来经济的基础

热门文章

  1. 用Word2003进行协同办公(转)
  2. python 如何给文件改名
  3. 计算差分方程的收敛点_时间序列分析第一章 差分方程
  4. 地磅称重——好的地磅称重软件都有哪些特点?
  5. linux root用户远程登录不上,linux禁止root用户远程登录
  6. IE首页被篡改成www.cnweb123.cn的修复办法
  7. vista系统服务器,Windows 7:二十个特色忘却Vista系统
  8. 怎么爬before after之间的内容_可见性有序性,Happens-before来搞定
  9. pythonmysql数据分析_Python操作Mysql数据库入门——数据导入pandas(数据分析准备)...
  10. 金山恢复大师专修硬盘数据:请给傅盛和猎豹一个机会!