简单的中国剩余定理。。。数论一顿套模板。。。
#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <climits>
#define maxn 800005
#define eps 1e-6
#define mod 10007
#define INF 99999999
#define lowbit(x) (x&(-x))
//#define lson o<<1, L, mid
//#define rson o<<1 | 1, mid+1, R
typedef long long LL;
using namespace std;
LL a[maxn], b[maxn], n;
void extend_gcd(LL a, LL b, LL &d, LL &x, LL &y)
{
if(b == 0) { d = a, x = 1, y = 0; }
else { extend_gcd(b, a%b, d, y, x), y -= x*(a/b); }
}
void extend_chinese_reminder(LL &a1, LL &b1)
{
LL x, y, g, tmp, i, a2, b2;
for(i = 1; i < n; i++) {
a2 = a[i], b2 = b[i];
extend_gcd(a1, a2, g, x, y);
tmp = a2/g;
x = x*(b2-b1)/g;
x = (x%tmp+tmp)%tmp;
b1 = a1*x+b1;
a1 = (a1*a2)/g;
b1 = (b1%a1+a1)%a1;
}
}
int main(void)
{
LL a1, b1, aa, i;
while(scanf("%I64d%I64d", &n, &aa), n!=0 || aa!=0) {
for(i = 0; i < n; i++) scanf("%I64d", &a[i]);
for(i = 0; i < n; i++) b[i] = a[i] - aa;
a1 = a[0], b1 = b[0];
extend_chinese_reminder(a1, b1);
printf("%I64d\n", b1);
}
}