题解 math

考场上脑袋懵的一批,于是就只打了个80分暴力,

正解是求得所有数和\(k\)\(gcd\)然后进行扩展。

Code

#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
namespace EMT{
	#define pf printf
	#define F(i,a,b) for(register int i=a;i<=b;i++)
	#define D(i,a,b) for(register int i=a;i>=b;i--)
	typedef long long ll;
	inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();return x*f;}
	inline int min(int a,int b){return a<b?a:b;}inline int max(int a,int b){return a>b?a:b;}
	inline void pi(int x){pf("%d ",x);}inline void pn(){pf("\n");}
	inline void file(){freopen("my.out","w",stdout);}
	const int N=1e7+100;
	int a[N],b[N],n,k,cnt;bool v[N];
	int q[N];
	inline int gcd(int a,int b){
		if(!b)return a;
		return gcd(b,a%b);
	}
	int g;
	inline short main(){
		n=read(),k=read();
		F(i,1,n)a[i]=read()%k;
		g=gcd(a[1],a[2]);
		F(i,3,n){
			g=gcd(g,a[i]);
		}
		F(i,0,k/gcd(g,k))v[i*g%k]=1;
		F(i,0,k-1)if(v[i])q[++cnt]=i;
		pi(cnt);pn();F(i,1,cnt)pi(q[i]);
		return 0;
	}
}
signed main(){return EMT::main();}
posted @ 2021-07-12 20:27  letitdown  阅读(44)  评论(0编辑  收藏  举报