{"problem":{"name":"D. Arpa and a list of numbers","description":{"content":"Arpa has found a list containing _n_ numbers. He calls a list bad if and only if it is not empty and _gcd_ (see notes section for more information) of numbers in the list is 1. Arpa can perform two t","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF851D"},"statements":[{"statement_type":"Markdown","content":"Arpa has found a list containing _n_ numbers. He calls a list bad if and only if it is not empty and _gcd_ (see notes section for more information) of numbers in the list is 1.\n\nArpa can perform two types of operations:\n\n*   Choose a number and delete it with cost _x_.\n*   Choose a number and increase it by 1 with cost _y_.\n\nArpa can apply these operations to as many numbers as he wishes, and he is allowed to apply the second operation arbitrarily many times on the same number.\n\nHelp Arpa to find the minimum possible cost to make the list good.\n\n## Input\n\nFirst line contains three integers _n_, _x_ and _y_ (1 ≤ _n_ ≤ 5·105, 1 ≤ _x_, _y_ ≤ 109) — the number of elements in the list and the integers _x_ and _y_.\n\nSecond line contains _n_ integers _a_1, _a_2, ..., _a__n_ (1 ≤ _a__i_ ≤ 106) — the elements of the list.\n\n## Output\n\nPrint a single integer: the minimum possible cost to make the list good.\n\n[samples]\n\n## Note\n\nIn example, number 1 must be deleted (with cost 23) and number 16 must increased by 1 (with cost 17).\n\nA _gcd_ (greatest common divisor) of a set of numbers is the maximum integer that divides all integers in the set. Read more about gcd [here](https://en.wikipedia.org/wiki/Greatest_common_divisor).","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"Arpa 找到了一个包含 $n$ 个数字的列表。他称一个列表为“坏的”，当且仅当它非空且列表中数字的 _gcd_（详见注释部分）为 $1$。\n\nArpa 可以执行两种操作：\n\nArpa 可以对任意多个数字应用这些操作，并且他允许对同一个数字无限次应用第二种操作。\n\n帮助 Arpa 找到使列表变“好”的最小可能代价。\n\n第一行包含三个整数 $n$、$x$ 和 $y$（$1 ≤ n ≤ 5·10^5$，$1 ≤ x, y ≤ 10^9$）— 列表中元素的个数以及整数 $x$ 和 $y$。\n\n第二行包含 $n$ 个整数 $a_1, a_2, ..., a_n$（$1 ≤ a_i ≤ 10^6$）— 列表的元素。\n\n请输出一个整数：使列表变“好”的最小可能代价。\n\n在示例中，数字 $1$ 必须被删除（代价为 $23$），数字 $16$ 必须增加 $1$（代价为 $17$）。\n\n一组数的 _gcd_（最大公约数）是能整除集合中所有整数的最大整数。有关 gcd 的更多信息，请参见此处。\n\n## Input\n\n第一行包含三个整数 $n$、$x$ 和 $y$（$1 ≤ n ≤ 5·10^5$，$1 ≤ x, y ≤ 10^9$）— 列表中元素的个数以及整数 $x$ 和 $y$。第二行包含 $n$ 个整数 $a_1, a_2, ..., a_n$（$1 ≤ a_i ≤ 10^6$）— 列表的元素。\n\n## Output\n\n请输出一个整数：使列表变“好”的最小可能代价。\n\n[samples]\n\n## Note\n\n在示例中，数字 $1$ 必须被删除（代价为 $23$），数字 $16$ 必须增加 $1$（代价为 $17$）。一组数的 _gcd_（最大公约数）是能整除集合中所有整数的最大整数。有关 gcd 的更多信息，请参见此处。","is_translate":true,"language":"Chinese"},{"statement_type":"Markdown","content":"**Definitions:**\n\n- Let $ n, x, y \\in \\mathbb{Z}^+ $, with $ 1 \\leq n \\leq 5 \\cdot 10^5 $, $ 1 \\leq x, y \\leq 10^9 $.\n- Let $ A = [a_1, a_2, \\dots, a_n] $, where $ a_i \\in \\mathbb{Z}^+ $, $ 1 \\leq a_i \\leq 10^6 $.\n\n**Operations:**\n\n1. **Delete** any element $ a_i $ at cost $ x $.\n2. **Increment** any element $ a_i $ by 1 any number of times; each increment costs $ y $.  \n   (Thus, increasing $ a_i $ to $ a_i + k $ costs $ k \\cdot y $.)\n\n**Goal:**\n\nTransform $ A $ into a list $ A' $ (possibly empty) such that:\n\n- $ A' $ is **not bad**, i.e., either:\n  - $ A' = \\emptyset $, or\n  - $ \\gcd(A') > 1 $.\n\nMinimize the total cost of operations to achieve this.\n\n**Objective:**\n\n$$\n\\min_{A'} \\left( x \\cdot (\\text{number of deletions}) + y \\cdot \\left( \\sum_{a_i \\in A'} (a_i' - a_i) \\right) \\right)\n$$\n\nsubject to:\n\n- $ A' $ is obtained from $ A $ by deleting some elements and incrementing others (non-negative integer increments),\n- $ A' = \\emptyset $ or $ \\gcd(A') > 1 $.\n\n**Note:** Incrementing is only allowed upward; no decrements.","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF851D","tags":["implementation"],"sample_group":[["4 23 17\n1 17 17 16","40"],["10 6 2\n100 49 71 73 66 96 8 60 41 63","10"]],"created_at":"2026-03-03 11:00:39"}}