Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <math.h>
- #include <algorithm>
- #include <map>
- #include <set>
- #include <string>
- #define form(i, n) for (int (i) = 0; (i) < (n); ++ (i))
- using namespace std;
- int gcd(int a, int b) {
- if (a < b)
- swap(a, b);
- if (a % b == 0)
- return b;
- else
- return gcd(b, a % b);
- }
- int main(void) {
- //ios_base::sync_with_stdio(false);
- //cin.tie(NULL);
- //freopen("input.txt", "r", stdin);
- int n, X;
- scanf("%d%d", &n, &X);
- int x[n + 1];
- for (int i = 0; i < n; ++ i)
- scanf("%d", x + i);
- x[n ++] = X;
- sort(x, x + n);
- int g = x[1] - x[0];
- for (int i = 2; i < n; ++ i)
- g = gcd(g, x[i] - x[i - 1]);
- printf("%d\n", g);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement