<form id="dlljd"></form>
        <address id="dlljd"><address id="dlljd"><listing id="dlljd"></listing></address></address>

        <em id="dlljd"><form id="dlljd"></form></em>

          <address id="dlljd"></address>
            <noframes id="dlljd">

              聯系我們 - 廣告服務 - 聯系電話:
              您的當前位置: > 關注 > > 正文

              世界訊息: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 中文字幕在线观看亚洲日韩