#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 1000000 + 10;
const double eps = 1e-15;
const int mod = 1e9 + 7;
int n, m, num, a1, b1, c1, d1, z, k;
vector<int> g[200100];
map<int, int> ma;
int a[100005], b[105];
int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); }
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &z);
    a[z % m] = 1;
  }
  int t = m;
  for (int i = 1; i < m; i++) {
    if (!a[i]) continue;
    t = gcd(i, t);
  }
  printf("%d\n", m / t);
  for (int i = 0; i < m; i++) {
    if (i * t >= m) break;
    printf("%d ", i * t);
  }
  return 0;
}
