StoneHaos

ff

May 17th, 2020
118
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5. #include <math.h>
  6. #include <algorithm>
  7. #include <map>
  8. #include <set>
  9. #include <string>
  10. #define form(i, n) for (int (i) = 0; (i) < (n); ++ (i))
  11.  
  12. using namespace std;
  13.  
  14. int gcd(int a, int b) {
  15.     if (a < b)
  16.         swap(a, b);
  17.     if (a % b == 0)
  18.         return b;
  19.     else
  20.         return gcd(b, a % b);
  21. }
  22.  
  23. int main(void) {
  24.     //ios_base::sync_with_stdio(false);
  25.     //cin.tie(NULL);
  26.    
  27.     //freopen("input.txt", "r", stdin);
  28.  
  29.     int n, X;
  30.     scanf("%d%d", &n, &X);
  31.     int x[n + 1];
  32.     for (int i = 0; i < n; ++ i)
  33.         scanf("%d", x + i);
  34.     x[n ++] = X;
  35.     sort(x, x + n);
  36.     int g = x[1] - x[0];
  37.     for (int i = 2; i < n; ++ i)
  38.         g = gcd(g, x[i] - x[i - 1]);
  39.     printf("%d\n", g);
  40.     return 0;
  41. }
RAW Paste Data