fork download
  1. #include<bits/stdc++.h>
  2. using namespace std ;
  3. int n;
  4. long long a[200005], res;
  5.  
  6. int main()
  7. {
  8. ios::sync_with_stdio(0);
  9. cin.tie(0);
  10. cout.tie(0);
  11. if(fopen("mm.inp","r"))
  12. {
  13. freopen("mm.inp","r",stdin);
  14. freopen("mm.out","w",stdout);
  15. }
  16. cin >> n;
  17. for(int i=0; i<n; i++)
  18. cin >> a[i];
  19.  
  20. sort(a, a+n);
  21. n = unique(a, a+n) - a;
  22.  
  23. res=0;
  24. for(int i=0; i<n; i++)
  25. {
  26. for(long long j = 2LL * a[i]; j <= a[n-1] + a[i]; j += a[i])
  27. {
  28. auto num_ptr = lower_bound(a + i, a + n, j);
  29. num_ptr--;
  30. long long x = *num_ptr;
  31. if (x >= j - a[i]) {
  32. res = max(res, x % a[i]);
  33. }
  34. }
  35. }
  36. cout << res;
  37. return 0 ;
  38. }
  39.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty