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