A11914 | Border
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 $n$ banknote denominations on Mars: the value of $i$ -th banknote is $a_i$ . Natasha has an infinite number of banknotes of each denomination.
Martians have $k$ fingers on their hands, so they use a number system with base $k$ . In addition, the Martians consider the digit $d$ (in the number system with base $k$ ) divine. Thus, if the last digit in Natasha's tax amount written in the number system with the base $k$ is $d$ , the Martians will be happy. Unfortunately, Natasha does not know the Martians' divine digit yet.
Determine for which values $d$ Natasha can make the Martians happy.
Natasha can use only her banknotes. Martians don't give her change.
There are $n$ banknote denominations on Mars: the value of $i$ -th banknote is $a_i$ . Natasha has an infinite number of banknotes of each denomination.
Martians have $k$ fingers on their hands, so they use a number system with base $k$ . In addition, the Martians consider the digit $d$ (in the number system with base $k$ ) divine. Thus, if the last digit in Natasha's tax amount written in the number system with the base $k$ is $d$ , the Martians will be happy. Unfortunately, Natasha does not know the Martians' divine digit yet.
Determine for which values $d$ Natasha can make the Martians happy.
Natasha can use only her banknotes. Martians don't give her change.
输入格式
The first line contains two integers $n$ and $k$ ( $1 \le n \le 100\,000$ , $2 \le k \le 100\,000$ ) — the number of denominations of banknotes and the base of the number system on Mars.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $1 \le a_i \le 10^9$ ) — denominations of banknotes on Mars.
All numbers are given in decimal notation.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $1 \le a_i \le 10^9$ ) — denominations of banknotes on Mars.
All numbers are given in decimal notation.
输出格式
On the first line output the number of values $d$ 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.
In the second line, output all these values in increasing order.
Print all numbers in decimal notation.
输入输出样例
输入 #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 $12$ , you will get $14_8$ in octal system. The last digit is $4_8$ .
If you take one banknote with the value of $12$ and one banknote with the value of $20$ , the total value will be $32$ . In the octal system, it is $40_8$ . The last digit is $0_8$ .
If you take two banknotes with the value of $20$ , the total value will be $40$ , this is $50_8$ in the octal system. The last digit is $0_8$ .
No other digits other than $0_8$ and $4_8$ can be obtained. Digits $0_8$ and $4_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.
If you take one banknote with the value of $12$ , you will get $14_8$ in octal system. The last digit is $4_8$ .
If you take one banknote with the value of $12$ and one banknote with the value of $20$ , the total value will be $32$ . In the octal system, it is $40_8$ . The last digit is $0_8$ .
If you take two banknotes with the value of $20$ , the total value will be $40$ , this is $50_8$ in the octal system. The last digit is $0_8$ .
No other digits other than $0_8$ and $4_8$ can be obtained. Digits $0_8$ and $4_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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted