fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define vodichc2 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  4. #define ll long long
  5. #define fr(i,a,b) for(long long i=a;i<=b;i++)
  6. #define frd(i,a,b) for(long long i=a;i>=b;i--)
  7. #define openfile if(fopen("Data.inp","r")) {freopen("Data.inp", "r", stdin); freopen("Data.out", "w", stdout);}
  8. ll n,a[200005];
  9. void doc()
  10. {
  11. cin >> n;
  12. fr(i,1,n) cin >> a[i];
  13. sort(a+1,a+n+1);
  14. }
  15. void xuly()
  16. {
  17. ll res=0;
  18. // fr(i,1,n)
  19. // fr(j,i+1,n)
  20. // {
  21. // res=max(a[j]%a[i],res);
  22. // }
  23. // cout << res;
  24. a[n+1]=1e9;
  25. fr(i,1,n)
  26. {
  27. for(ll t=a[i];t<=a[n]+a[i];t+=a[i])
  28. {
  29. ll j=lower_bound(a+1,a+n+2,t)-a;
  30. j--;
  31. if(j>0)
  32. {
  33. if(a[j]>a[i]) res=max(res,a[j]%a[i]);
  34. }
  35. }
  36. }
  37. cout << res;
  38. }
  39. signed main()
  40. {
  41. vodichc2
  42. openfile
  43. doc();
  44. xuly();
  45. }
  46.  
  47.  
  48.  
  49. /*
  50.  
  51.  
  52.   ¦¦¦¦¦¦¦¦¦¦¦¦
  53.   ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
  54.   ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
  55.   ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
  56.   ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦ ¦¦¦¦¦¦
  57.   ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
  58.   ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
  59.   ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
  60.   ¦¦¦¦¦¦¦¦¦¦¦¦
  61.   ¦¦¦¦¦¦¦¦¦¦
  62.   ¦¦¦¦¦¦ ¦¦¦¦
  63.   ¦¦¦¦¦¦¦¦¦¦¦¦¦¦
  64.   ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
  65.   ¦¦¦¦ ¦¦¦¦¦¦¦¦¦¦
  66.   ¦¦¦¦¦¦¦¦ ¦¦¦¦¦¦¦¦¦¦
  67.   ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
  68.   ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
  69.   ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦ ¦¦¦¦
  70.   ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦ ¦¦¦¦
  71.   ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦ ¦¦¦¦
  72.   ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦ ¦¦
  73.   ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦ ¦¦¦¦
  74.   ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦NGUYEN THANH PHONG¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
  75.   ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦ ¦¦
  76.   ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦LE KHIET¦¦¦¦¦¦¦¦¦¦¦¦¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦ ¦¦
  77.   ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
  78.   ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦ ¦¦ ¦¦¦¦¦¦
  79.   ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
  80.   ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
  81.   ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
  82.   ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
  83.   ¦¦¦¦¦¦¦¦¦¦
  84.   ¦¦¦¦¦¦¦¦¦¦
  85.   ¦¦ ¦¦
  86.   ¦¦ ¦¦
  87.   ¦¦ ¦¦
  88.   ¦¦ ¦¦
  89.   ¦¦¦¦¦¦¦¦ ¦¦ ¦¦
  90.   ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
  91. */
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty