联系我们 - 广告服务 - 联系电话:
您的当前位置: > 关注 > > 正文

世界讯息:E. Border是什么?拓展欧几里得+mod分析

来源:CSDN 时间:2022-12-19 10:20:13

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 812 20

Output

Copy

20 4 

Input

Copy

3 1010 20 30

Output

Copy

10 

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.

#includeusing namespace std;typedef long long ll;#define rep(i,a,b) for(int i=a;i=a;i--)set 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::iterator it;    for(it=st.begin();it!=st.end();it++){        printf("%lld%c",*it,it==st.end()?"\n":" ");    }    return 0;}
责任编辑:

标签: 欧几里得

相关推荐:

精彩放送:

新闻聚焦
Top