E. Border —— 想法

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.

这个我并不会= =!,是从别人的博客那里看来的
我的理解是,它所有的可能性肯定是所有数的gcd,此外没有其他情况,然后只要for k遍就好了,这样就包含了所有的可能性,再放到一个set里面

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    ll g=0,x;
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&x);
        if(g)
            g=__gcd(g,x);
        else
            g=x;
    }
    ll sta=g;
    set<ll>st;
    for(int i=1;i<=k;i++)
    {
        st.insert(sta%k);
        sta+=g;
    }
    set<ll>::iterator it;
    printf("%d\n",st.size());
    for(it=st.begin();it!=st.end();it++)
    {
        printf("%lld%c",*it,it==st.end()?'\n':' ');
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值