A11887 | Appropriate Team
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Since next season are coming, you'd like to form a team from two or three participants. There are $n$ candidates, the $i$ -th candidate has rank $a_i$ . But you have weird requirements for your teammates: if you have rank $v$ and have chosen the $i$ -th and $j$ -th candidate, then $GCD(v, a_i) = X$ and $LCM(v, a_j) = Y$ must be met.
You are very experienced, so you can change your rank to any non-negative integer but $X$ and $Y$ are tied with your birthdate, so they are fixed.
Now you want to know, how many are there pairs $(i, j)$ such that there exists an integer $v$ meeting the following constraints: $GCD(v, a_i) = X$ and $LCM(v, a_j) = Y$ . It's possible that $i = j$ and you form a team of two.
$GCD$ is the greatest common divisor of two number, $LCM$ — the least common multiple.
You are very experienced, so you can change your rank to any non-negative integer but $X$ and $Y$ are tied with your birthdate, so they are fixed.
Now you want to know, how many are there pairs $(i, j)$ such that there exists an integer $v$ meeting the following constraints: $GCD(v, a_i) = X$ and $LCM(v, a_j) = Y$ . It's possible that $i = j$ and you form a team of two.
$GCD$ is the greatest common divisor of two number, $LCM$ — the least common multiple.
输入格式
First line contains three integers $n$ , $X$ and $Y$ ( $1 \le n \le 2 \cdot 10^5$ , $1 \le X \le Y \le 10^{18}$ ) — the number of candidates and corresponding constants.
Second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ( $1 \le a_i \le 10^{18}$ ) — ranks of candidates.
Second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ( $1 \le a_i \le 10^{18}$ ) — ranks of candidates.
输出格式
Print the only integer — the number of pairs $(i, j)$ such that there exists an integer $v$ meeting the following constraints: $GCD(v, a_i) = X$ and $LCM(v, a_j) = Y$ . It's possible that $i = j$ .
输入输出样例
输入 #1
12 2 2 1 2 3 4 5 6 7 8 9 10 11 12
输出 #1
12
输入 #2
12 1 6 1 3 5 7 9 11 12 10 8 6 4 2
输出 #2
30
In the first example next pairs are valid: $a_j = 1$ and $a_i = [2, 4, 6, 8, 10, 12]$ or $a_j = 2$ and $a_i = [2, 4, 6, 8, 10, 12]$ . The $v$ in both cases can be equal to $2$ .
In the second example next pairs are valid:
- $a_j = 1$ and $a_i = [1, 5, 7, 11]$ ;
- $a_j = 2$ and $a_i = [1, 5, 7, 11, 10, 8, 4, 2]$ ;
- $a_j = 3$ and $a_i = [1, 3, 5, 7, 9, 11]$ ;
- $a_j = 6$ and $a_i = [1, 3, 5, 7, 9, 11, 12, 10, 8, 6, 4, 2]$ .
In the second example next pairs are valid:
- $a_j = 1$ and $a_i = [1, 5, 7, 11]$ ;
- $a_j = 2$ and $a_i = [1, 5, 7, 11, 10, 8, 4, 2]$ ;
- $a_j = 3$ and $a_i = [1, 3, 5, 7, 9, 11]$ ;
- $a_j = 6$ and $a_i = [1, 3, 5, 7, 9, 11, 12, 10, 8, 6, 4, 2]$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted