time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 aiai. 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.

Input

The first line contains two integers nn and kk (1≤n≤1000001≤n≤100000, 2≤k≤1000002≤k≤100000) — the number of denominations of banknotes and the base of the number system on Mars.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) — denominations of banknotes on Mars.

All numbers are given in decimal notation.

Output

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.

Examples
input

Copy
2 8
12 20
output

Copy
2
0 4
input

Copy
3 10
10 20 30
output

Copy
1
0
Note

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

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

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 408408. The last digit is 0808.

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

No other digits other than 0808 and 4848 can be obtained. Digits 0808 and 4848 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.

  给出n种钞票的面值(十进制下),每种钞票数量inf,问在k进制下能组合成的所有面额的最低位的数有哪些。

这就等价于是  a1*x1+a2*x2+......+an*xn=g  ,g就是组合成的钞票面值,由裴蜀定理可知d=y*gcd(a1,a2,,,an),

我们只要求出gcd(a1,a2,,,,,,an),然后把所有情况(y<k)扫一下就好了。

 #include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b){return b==?a:gcd(b,a%b);}
set<long long >S;
int main(){
long long a,n,k,i,j,g=;
cin>>n>>k;
for(i=;i<=n;++i){
cin>>a;
g=gcd(g,a);
}
for(i=,j=;j<=k;j++,i+=g) S.insert(i%k);
cout<<S.size()<<endl;
for(set<long long >::iterator it=S.begin();it!=S.end();++it){
printf("%lld%c",*it,it==S.end()?'\n':' ');
}
return ;
}

CF-499div2-E-裴蜀定理的更多相关文章

  1. 【BZOJ-2299】向量 裴蜀定理 + 最大公约数

    2299: [HAOI2011]向量 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 1118  Solved: 488[Submit][Status] ...

  2. 【BZOJ-1441】Min 裴蜀定理 + 最大公约数

    1441: Min Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 471  Solved: 314[Submit][Status][Discuss] De ...

  3. BZOJ-2257 瓶子和燃料 分解因数+数论方面乱搞(裴蜀定理)

    一开始真没想出解法...后来发现那么水.... 2257: [Jsoi2009]瓶子和燃料 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 970 So ...

  4. 【BZOJ】1441: Min(裴蜀定理)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1441 这东西竟然还有个名词叫裴蜀定理................ 裸题不说....<初等数 ...

  5. BZOJ 2257: [Jsoi2009]瓶子和燃料 裴蜀定理

    2257: [Jsoi2009]瓶子和燃料 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/p ...

  6. BZOJ 2257: [Jsoi2009]瓶子和燃料【数论:裴蜀定理】

    2257: [Jsoi2009]瓶子和燃料 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1326  Solved: 815[Submit][Stat ...

  7. 【Wannafly挑战赛22A计数器】【裴蜀定理】

    https://www.nowcoder.com/acm/contest/160/A 题目描述 有一个计数器,计数器的初始值为0,每次操作你可以把计数器的值加上a1,a2,...,an中的任意一个整数 ...

  8. [BZOJ 2299][HAOI 2011]向量 题解(裴蜀定理)

    [BZOJ 2299][HAOI 2011]向量 Description 给你一对数a,b,你可以任意使用(a,b), (a,-b), (-a,b), (-a,-b), (b,a), (b,-a), ...

  9. hdu 6444 网络赛 Neko's loop(单调队列 + 裴蜀定理)题解

    题意:有编号为0~n-1的n个游戏,每个活动都有一个价值(可为负),给你m,s和k,你可以从任意一个编号开始玩,但是下一个游戏必须是编号为(i + k)%n的游戏,你最多能玩m次游戏,问你如果最后你手 ...

  10. 【裴蜀定理】【CF1091C】 New Year and the Sphere Transmission

    Description 有 \(n\) 个人围成一个圈,按照顺时针从 \(1\) 到 \(n\) 编号.第 \(1\) 个人会拿到一个球,他指定一个数字 \(k\),然后会将球传给他后面顺指针数第 \ ...

随机推荐

  1. 一起来全面解析5G网络领域最关键的十大技术

    提到5G,很多人的第一印象就是它的网络速度快.延时性低.带宽大,没错,这就是5G时代的特点!5G作为第五代移动通信网络,其峰值理论传输速度可达每秒数十Gb,这比4G网络的传输速度快数百倍,整部超高画质 ...

  2. keepalived+MySQL高可用集群

    基于keepalived搭建MySQL的高可用集群   MySQL的高可用方案一般有如下几种: keepalived+双主,MHA,MMM,Heartbeat+DRBD,PXC,Galera Clus ...

  3. Python学习笔记之面向对象编程(三)Python类的魔术方法

    python类中有一些方法前后都有两个下划线,这类函数统称为魔术方法.这些方法有特殊的用途,有的不需要我们自己定义,有的则通过一些简单的定义可以实现比较神奇的功能 我主要把它们分为三个部分,下文也是分 ...

  4. Educational Codeforces Round 21 Problem F (Codeforces 808F) - 最小割 - 二分答案

    Digital collectible card games have become very popular recently. So Vova decided to try one of thes ...

  5. 不明原因报错集中处理:Undefined

    1, NSGenericException错误 Terminating app due to uncaught exception 'NSGenericException', reason: '*** ...

  6. [BZOJ4244]邮戳拉力赛

    Description IOI铁路是由N+2个站点构成的直线线路.这条线路的车站从某一端的车站开始顺次标号为0...N+1. 这条路线上行驶的电车分为上行电车和下行电车两种,上行电车沿编号增大方向行驶 ...

  7. gulp常用命令

    gulp 默认的执行的命名文件为gulpfile 换成其他命名就识别不了 因为需要安装两次gulp或者说其他插件,一个是全局-g安装一个是本地目录安装, 本地目录安装时目录移动或者名字被改变就会失效提 ...

  8. java画流程图【思路】

    java计算整数输入 <样例 画的第一张流程图 把脑子里的东西能清晰的表现出来 学编程必备

  9. python 中的object与type的关系

    object 和 type的关系很像鸡和蛋的关系,先有object还是先有type没法说,obejct和type是共生的关系,必须同时出现的. 在看下去之前,也要请先明白,在Python里面,所有的东 ...

  10. win10 操作系统 修改桌面图标

    桌面右击出现菜单后,点击个性化: 点击左边菜单的主题,点击桌面图标设置,在新窗口中选择需要显示的图标接口 details please check following screenshot