#include<bits/stdc++.h>
using namespace std;
int mod_value(int a[], int n)
{
int ans = 0, i, j;
sort(a, a+n);
for(i=n-2;i>=0;i--)
{
if(ans >= a[i])
break;
if(a[i] == a[i+1])
continue;
for(j=2*a[i];j<=a[n-1]+a[i];j+=a[i])
{
int index = lower_bound(a, a+n, j) - a;
ans = max(ans, a[index-1]%a[i]);
}
}
return ans;
}
int main()
{
int n, i;
cout << "Enter Array Size :: ";
cin >> n;
int a[n];
cout << "Enter Array Element :: " << endl;
for(i=0;i<n;i++)
cin >> a[i];
int r = mod_value(a, n);
cout << "Maximum Modulo Value :: " << r << endl;
return 0;
}
Comments
Post a Comment