CF1010C.Border

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Astronaut Natasha arrived on Mars. She knows that the Martians are very poor aliens. To ensure a better life for the Mars citizens, their emperor decided to take tax from every tourist who visited the planet. Natasha is the inhabitant of Earth, therefore she had to pay the tax to enter the territory of Mars.

There are nn banknote denominations on Mars: the value of ii-th banknote is aia_i. Natasha has an infinite number of banknotes of each denomination.

Martians have kk fingers on their hands, so they use a number system with base kk. In addition, the Martians consider the digit dd (in the number system with base kk) divine. Thus, if the last digit in Natasha's tax amount written in the number system with the base kk is dd, the Martians will be happy. Unfortunately, Natasha does not know the Martians' divine digit yet.

Determine for which values dd Natasha can make the Martians happy.

Natasha can use only her banknotes. Martians don't give her change.

宇航员娜塔莎抵达了火星。她知道火星人是非常贫穷的外星人。为了改善火星公民的生活,他们的皇帝决定向每一位访问该星球的游客征税。娜塔莎是地球居民,因此她必须缴纳税款才能进入火星领土。

火星上有 nn 种纸币面额:第 ii 种纸币的面值为 aia_i。娜塔莎拥有每种面额的无限张纸币。

火星人每只手有 kk 根手指,因此他们使用以 kk 为底的进位制。此外,火星人认为数字 dd(在以 kk 为底的进位制中)是“神圣的”。因此,若娜塔莎所缴税款金额用 kk 进制表示时,其末位数字恰好为 dd,火星人便会感到高兴。不幸的是,娜塔莎目前尚不知道火星人的神圣数字 dd 是多少。

请确定:对于哪些 dd 值,娜塔莎能够使火星人感到高兴?

娜塔莎只能使用她自己所拥有的纸币。火星人不会给她找零。

输入格式

The first line contains two integers nn and kk (1≤n≤100 0001 \le n \le 100\,000, 2≤k≤100 0002 \le k \le 100\,000) — the number of denominations of banknotes and the base of the number system on Mars.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1091 \le a_i \le 10^9) — denominations of banknotes on Mars.

All numbers are given in decimal notation.

第一行包含两个整数 nn 和 kk(1≤n≤100 0001 \le n \le 100\,000,2≤k≤100 0002 \le k \le 100\,000)—— 分别表示火星上纸币的面额种类数以及火星所用数制的进制。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1091 \le a_i \le 10^9)—— 表示火星上纸币的各个面额。

所有数字均以十进制给出。

输出格式

On the first line output the number of values dd for which Natasha can make the Martians happy.

In the second line, output all these values in increasing order.

Print all numbers in decimal notation.

第一行输出 Natasha 能够使火星人开心的数值 dd 的个数。

第二行按升序输出所有这些数值。

所有数字均以十进制表示。

输入输出样例

  • 输入#1

    2 8
    12 20

    输出#1

    2
    0 4
  • 输入#2

    3 10
    10 20 30

    输出#2

    1
    0

说明/提示

Consider the first test case. It uses the octal number system.

If you take one banknote with the value of 1212, you will get 14814_8 in octal system. The last digit is 484_8.

If you take one banknote with the value of 1212 and one banknote with the value of 2020, the total value will be 3232. In the octal system, it is 40840_8. The last digit is 080_8.

If you take two banknotes with the value of 2020, the total value will be 4040, this is 50850_8 in the octal system. The last digit is 080_8.

No other digits other than 080_8 and 484_8 can be obtained. Digits 080_8 and 484_8 could also be obtained in other ways.

The second test case uses the decimal number system. The nominals of all banknotes end with zero, so Natasha can give the Martians only the amount whose decimal notation also ends with zero.

考虑第一个测试用例,它使用八进制数制。

若取一张面值为 1212 的纸币,则总金额为 1212,在八进制下表示为 14814_8,其末位数字为 484_8。

若取一张面值为 1212 的纸币和一张面值为 2020 的纸币,则总金额为 3232,在八进制下表示为 40840_8,其末位数字为 080_8。

若取两张面值为 2020 的纸币,则总金额为 4040,在八进制下表示为 50850_8,其末位数字为 080_8。

除 080_8 和 484_8 外,无法得到其他末位数字。而 080_8 和 484_8 还可通过其他方式得到。

第二个测试用例使用十进制数制。所有纸币的面额均以 00 结尾,因此娜塔莎只能向火星人支付一个其十进制表示也以 00 结尾的金额。

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

首页