//#Chetan Patil [[email protected]] [+919503368362]
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pi(x) cout<<x;
#define ps(x) cout<<x<<" ";
#define pnl(x) cout<<x<<"\n";
#define for0(n) for(i=0;i<n;i++)
#define for1(n) for(i=1;i<=n;i++)
#define m(x) memset(x,0,sizeof x);
#define nl cout<<"\n";
#define mp make_pair
#define pb push_back
#define fr first
#define se second
#define Inf 1e16
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll test,h,i,j,xy,flag=0,n,p,q,u,d,count,o1=0,o2=0,o3,e,l,r,x,y,m,z,max1,x1,y1,k,x2,y2,z1,z2,sum;
cin>>n;
vector<ll>a(2000002,0),left,right;
left=right=a;
for(i=0;i<n;i++){
cin>>x;
left[x]=x;
}
right=left;
for(i=1;i<=2000000;i++){
if(left[i]==0){
left[i]=left[i-1];
}
}
max1=0;
for(i=1;i<=2000000;i++){
if(left[i]==i){
for(j=i;j<=2000000;j+=i){
if(left[j-1]>=i){
max1=max(left[j-1]%i,max1);
}
}
}
}
cout<<max1<<"\n";
return 0;
}
368. Largest Divisible Subset | 377. Combination Sum IV |
322. Coin Change | 307. Range Sum Query - Mutable |
287. Find the Duplicate Number | 279. Perfect Squares |
275. H-Index II | 274. H-Index |
260. Single Number III | 240. Search a 2D Matrix II |
238. Product of Array Except Self | 229. Majority Element II |
222. Count Complete Tree Nodes | 215. Kth Largest Element in an Array |
198. House Robber | 153. Find Minimum in Rotated Sorted Array |
150. Evaluate Reverse Polish Notation | 144. Binary Tree Preorder Traversal |
137. Single Number II | 130. Surrounded Regions |
129. Sum Root to Leaf Numbers | 120. Triangle |
102. Binary Tree Level Order Traversal | 96. Unique Binary Search Trees |
75. Sort Colors | 74. Search a 2D Matrix |
71. Simplify Path | 62. Unique Paths |
50. Pow(x, n) | 43. Multiply Strings |