fork download
  1. #include<bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4.  
  5. using namespace __gnu_pbds;
  6. using namespace std;
  7.  
  8. #define ll long long
  9. #define all(x) x.begin(),x.end()
  10.  
  11. typedef tree<
  12. int,
  13. null_type,
  14. greater<int>,
  15. rb_tree_tag,
  16. tree_order_statistics_node_update
  17. > ordered_set;
  18.  
  19. ll MOD = 1000000007;
  20.  
  21. ll oo = 1e15;
  22.  
  23. ll const N = 200000;
  24.  
  25. ll dp[N][4];
  26.  
  27. string s;
  28.  
  29. ll go(ll idx,ll mod) {
  30. //base case
  31. if (idx==s.size()) return mod==0;
  32. //dp check
  33. ll & res = dp[idx][mod];
  34. if (~res) return res;
  35. //transition
  36. ll dig = s[idx]-'0';
  37. ll gain1 = ((mod+dig)%3)==0;
  38. ll ch1 = go(idx+1,3) + gain1;
  39. ll ch2 = go(idx+1,(mod+dig)%3);
  40. return res = max(ch1,ch2);
  41. }
  42.  
  43. void solve() {
  44. ll n;cin>>n;
  45. ll a[n];
  46. for (ll i=0;i<n;i++)cin>>a[i];
  47. ll diff[n];
  48. ll ans = 0;
  49. for (ll i=0;i<n-1;i++) {
  50. diff[i] = abs(a[i+1]-a[i]);
  51. ans = __gcd(ans,diff[i]);
  52. }
  53. cout<<ans<<endl;
  54. }
  55.  
  56. signed main() {
  57. ios_base::sync_with_stdio(false);
  58. cin.tie(NULL);
  59. cout.tie(NULL);
  60. #ifndef ONLINE_JUDGE
  61. freopen("input.txt", "r",stdin);
  62. freopen("output.txt", "w",stdout);
  63. #endif
  64. bool calc = false;
  65. // calc = true;
  66. if (calc) {
  67. cout << N*2*2*4 << endl;
  68. cout << (1ll << (17)) << endl;
  69. return 0;
  70. }
  71. ll t = 1;
  72. // cin >> t;
  73. while (t--) {
  74. solve();
  75. }
  76. }
  77.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
1