CF1016G.Appropriate Team

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Since next season are coming, you'd like to form a team from two or three participants. There are nn candidates, the ii-th candidate has rank aia_i. But you have weird requirements for your teammates: if you have rank vv and have chosen the ii-th and jj-th candidate, then GCD(v,ai)=XGCD(v, a_i) = X and LCM(v,aj)=YLCM(v, a_j) = Y must be met.

You are very experienced, so you can change your rank to any non-negative integer but XX and YY are tied with your birthdate, so they are fixed.

Now you want to know, how many are there pairs (i,j)(i, j) such that there exists an integer vv meeting the following constraints: GCD(v,ai)=XGCD(v, a_i) = X and LCM(v,aj)=YLCM(v, a_j) = Y. It's possible that i=ji = j and you form a team of two.

GCDGCD is the greatest common divisor of two number, LCMLCM — the least common multiple.

由于新赛季即将到来,你希望从两名或三名参与者中组建一支队伍。现有 nn 名候选人,其中第 ii 名候选人的排名为 aia_i。但你对队友有特殊要求:若你的排名为 vv,且你选中了第 ii 名和第 jj 名候选人,则必须满足 GCD(v,ai)=XGCD(v, a_i) = X 且 LCM(v,aj)=YLCM(v, a_j) = Y。

你经验非常丰富,因此可将自身排名调整为任意非负整数;但 XX 和 YY 与你的生日绑定,故其值固定不变。

现在你想知道:有多少对 (i,j)(i, j) 满足——存在某个整数 vv,使得约束条件 GCD(v,ai)=XGCD(v, a_i) = X 与 LCM(v,aj)=YLCM(v, a_j) = Y 同时成立?注意 i=ji = j 是允许的,此时你将组建一支两人队伍。

其中 GCDGCD 表示两个数的最大公约数,LCMLCM 表示两个数的最小公倍数。

输入格式

First line contains three integers nn, XX and YY (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5, 1≤X≤Y≤10181 \le X \le Y \le 10^{18}) — the number of candidates and corresponding constants.

Second line contains nn space separated integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤10181 \le a_i \le 10^{18}) — ranks of candidates.

第一行包含三个整数 nn、XX 和 YY(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5,1≤X≤Y≤10181 \le X \le Y \le 10^{18})——分别为候选人数量及对应的常数。

第二行包含 nn 个用空格分隔的整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤10181 \le a_i \le 10^{18})——表示各位候选人的排名。

输出格式

Print the only integer — the number of pairs (i,j)(i, j) such that there exists an integer vv meeting the following constraints: GCD(v,ai)=XGCD(v, a_i) = X and LCM(v,aj)=YLCM(v, a_j) = Y. It's possible that i=ji = j.

输出唯一的整数——满足如下条件的数对 (i,j)(i, j) 的个数:存在整数 vv,使得 GCD(v,ai)=XGCD(v, a_i) = X 且 LCM(v,aj)=YLCM(v, a_j) = Y。允许 i=ji = 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: aj=1a_j = 1 and ai=[2,4,6,8,10,12]a_i = [2, 4, 6, 8, 10, 12] or aj=2a_j = 2 and ai=[2,4,6,8,10,12]a_i = [2, 4, 6, 8, 10, 12]. The vv in both cases can be equal to 22.

In the second example next pairs are valid:

  • aj=1a_j = 1 and ai=[1,5,7,11]a_i = [1, 5, 7, 11];
  • aj=2a_j = 2 and ai=[1,5,7,11,10,8,4,2]a_i = [1, 5, 7, 11, 10, 8, 4, 2];
  • aj=3a_j = 3 and ai=[1,3,5,7,9,11]a_i = [1, 3, 5, 7, 9, 11];
  • aj=6a_j = 6 and ai=[1,3,5,7,9,11,12,10,8,6,4,2]a_i = [1, 3, 5, 7, 9, 11, 12, 10, 8, 6, 4, 2].

在第一个例子中,以下数对是合法的:aj=1a_j = 1 且 ai=[2,4,6,8,10,12]a_i = [2, 4, 6, 8, 10, 12],或 aj=2a_j = 2 且 ai=[2,4,6,8,10,12]a_i = [2, 4, 6, 8, 10, 12]。在这两种情况下,vv 均可取值为 22。

在第二个例子中,以下数对是合法的:

  • aj=1a_j = 1 且 ai=[1,5,7,11]a_i = [1, 5, 7, 11];
  • aj=2a_j = 2 且 ai=[1,5,7,11,10,8,4,2]a_i = [1, 5, 7, 11, 10, 8, 4, 2];
  • aj=3a_j = 3 且 ai=[1,3,5,7,9,11]a_i = [1, 3, 5, 7, 9, 11];
  • aj=6a_j = 6 且 ai=[1,3,5,7,9,11,12,10,8,6,4,2]a_i = [1, 3, 5, 7, 9, 11, 12, 10, 8, 6, 4, 2]。

输入解题思路,AI测评打分。不知道怎么写?

首页