Codeforces Round #499 (Div. 2) E. Border(贝祖定理)
题解思路:
对于每个啊a[i]先对k取余;
贝祖定理可知若 a1*x1+a2*x2+.....+an*xn==c;
则 c|gcd(a1,a2,a3.....an);
所以ans=(gcd*(0->k-1))%k;
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<map>
#include<queue>
#include<stack>
#include<set>
#define ll long long
#define int long long
#define mem(a,b) memset(a,b,sizeof(a))
const int maxn=1e5+50;
using namespace std;
int gcd(int a,int b)
{
return b==0?a:gcd(b,a%b);
}
set<int>q;
#undef int
int main(){
#define int long long
int n,k,g;
cin>>n>>k;
cin>>g;
for(int i=2;i<=n;i++)
{
int now;
cin>>now;
g=gcd(g,now);
}
for(int i=0;i<k;i++)
{
q.insert((g*i)%k);
}
cout<<q.size()<<endl;
set<int>::iterator iter;
for(iter=q.begin();iter!=q.end();)
{
cout<<*iter;
++iter!=q.end()?cout<<" ":cout<<endl;
}
return 0;
}