Advertisement
erfanul007

Untitled

Jan 11th, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long int ll;
  5. typedef unsigned long long int ull;
  6. typedef vector<int> vi;
  7. typedef vector<vi> vvi;
  8. typedef pair<ll,ll> pll;
  9. typedef vector< pll > vpll;
  10. typedef set<int> sti;
  11.  
  12. #define pb push_back
  13. #define pob pop_back
  14. #define mp make_pair
  15. #define ff first
  16. #define ss second
  17. #define loop1(i,n) for(int i=1; i<=int(n); i++)
  18. #define loop(i,y) for(int i=0; i<int(y); i++)
  19. #define rloop(i,y) for(int i=int(y); i>0; i--)
  20. #define rloop1(i,y) for(int i=int(y)-1; i>=0; i--)
  21. #define read() freopen("input.txt", "r", stdin)
  22. #define write() freopen("output.txt", "w", stdout)
  23. #define cspf(i) printf("Case %d: ", i)
  24. /// Constants
  25. #define eps 1e-9
  26. #define PI acos(-1.0) // 3.1415926535897932
  27.  
  28. ll a[100009];
  29. int main()
  30. {
  31. ll n,i,j,tgc,gc=0;
  32. cin>>n;
  33. loop(i,n){
  34. cin>>a[i];
  35. }
  36. for(i=0,j=n-1;i<=j;i++,j--){
  37. if(a[i]!=a[j]){
  38. tgc=abs(a[i]-a[j]);
  39. if(gc==0)
  40. gc=tgc;
  41. else
  42. gc=__gcd(gc,tgc);
  43. }
  44. }
  45. if(gc)
  46. cout<<gc<<endl;
  47. else
  48. cout<<"-1"<<endl;
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement