A13393 | Orac and LCM
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
For the multiset of positive integers $s=\{s_1,s_2,\dots,s_k\}$ , define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of $s$ as follow:
- $\gcd(s)$ is the maximum positive integer $x$ , such that all integers in $s$ are divisible on $x$ .
- $\textrm{lcm}(s)$ is the minimum positive integer $x$ , that divisible on all integers from $s$ .
For example, $\gcd(\{8,12\})=4,\gcd(\{12,18,6\})=6$ and $\textrm{lcm}(\{4,6\})=12$ . Note that for any positive integer $x$ , $\gcd(\{x\})=\textrm{lcm}(\{x\})=x$ .
Orac has a sequence $a$ with length $n$ . He come up with the multiset $t=\{\textrm{lcm}(\{a_i,a_j\})\ |\ i<j\}$ , and asked you to find the value of $\gcd(t)$ for him. In other words, you need to calculate the GCD of LCMs of all pairs of elements in the given sequence.
- $\gcd(s)$ is the maximum positive integer $x$ , such that all integers in $s$ are divisible on $x$ .
- $\textrm{lcm}(s)$ is the minimum positive integer $x$ , that divisible on all integers from $s$ .
For example, $\gcd(\{8,12\})=4,\gcd(\{12,18,6\})=6$ and $\textrm{lcm}(\{4,6\})=12$ . Note that for any positive integer $x$ , $\gcd(\{x\})=\textrm{lcm}(\{x\})=x$ .
Orac has a sequence $a$ with length $n$ . He come up with the multiset $t=\{\textrm{lcm}(\{a_i,a_j\})\ |\ i<j\}$ , and asked you to find the value of $\gcd(t)$ for him. In other words, you need to calculate the GCD of LCMs of all pairs of elements in the given sequence.
输入格式
The first line contains one integer $n\ (2\le n\le 100\,000)$ .
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ( $1 \leq a_i \leq 200\,000$ ).
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ( $1 \leq a_i \leq 200\,000$ ).
输出格式
Print one integer: $\gcd(\{\textrm{lcm}(\{a_i,a_j\})\ |\ i<j\})$ .
输入输出样例
输入 #1
2 1 1
输出 #1
1
输入 #2
4 10 24 40 80
输出 #2
40
输入 #3
10 540 648 810 648 720 540 594 864 972 648
输出 #3
54
For the first example, $t=\{\textrm{lcm}(\{1,1\})\}=\{1\}$ , so $\gcd(t)=1$ .
For the second example, $t=\{120,40,80,120,240,80\}$ , and it's not hard to see that $\gcd(t)=40$ .
For the second example, $t=\{120,40,80,120,240,80\}$ , and it's not hard to see that $\gcd(t)=40$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted