Saleh127

uva 10407.cpp

Jun 21st, 2020
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define test int t; cin>>t; while (t--)
  4. #define ll long long int
  5. #define Faster ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  6. ll x[10000];
  7. ll gcd(ll a,ll c)
  8. {
  9. while(c)
  10. {
  11. a=a%c;
  12. swap(a,c);
  13. }
  14. return a;
  15. }
  16. int main()
  17. {
  18. Faster
  19. while(scanf("%lld ",&x[0])!=EOF)
  20. {
  21. if(x[0]==0) break;
  22. ll c=1;
  23. while(1)
  24. {
  25. scanf("%lld ",&x[c]);
  26. if(x[c]==0) break;
  27. else c++;
  28. }
  29. ll ans=0;
  30. for(ll i=1;i<c;i++)
  31. {
  32. ll d=x[i]-x[i-1];
  33. ans=gcd(ans,d);
  34. }
  35. if(ans<0) ans=ans*(-1);
  36. printf("%lld\n",ans);
  37. }
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment