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 ai
. 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.
Input
The first line contains two integers n
and k (1≤n≤100000, 2≤k≤100000
) — the number of denominations of banknotes and the base of the number system on Mars.
The second line contains n
integers a1,a2,…,an (1≤ai≤109
) — denominations of banknotes on Mars.
All numbers are given in decimal notation.
Output
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.
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 12
, you will get 148 in octal system. The last digit is 48
.
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 408. The last digit is 08
.
If you take two banknotes with the value of 20
, the total value will be 40, this is 508 in the octal system. The last digit is 08
.
No other digits other than 08
and 48 can be obtained. Digits 08 and 48
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.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
set<ll> st;
ll gcd(ll a,ll b){
return b==0?a:gcd(b,a%b);
}
/*
相似题:蓝桥杯,包子凑数
核心思想:a1*x1+a2*x2+...+an*xn==gcd(a1,a2,...,an)*? <---原理:拓展欧几里得
也就是他们能凑出来的树肯定是,gcd的倍数,
然后在mod系下的话,只要枚举到mod就好了
当时只想着把他们都转化成mod系下的数字,然后在进行计算,事实就是这样会更麻烦
*/
int main(){
int n,m;
scanf("%d %d",&n,&m);
ll val,G;
rep(i,1,n+1){
scanf("%lld",&val);
if(i==1)G=val;
else G=gcd(G,val);
}
for(ll i=0,j=0;j<=m;j++,i+=G){
st.insert(i%m);
}
printf("%d\n",st.size());
set<ll>::iterator it;
for(it=st.begin();it!=st.end();it++){
printf("%lld%c",*it,it==st.end()?'\n':' ');
}
return 0;
}