maximum modulo problem

I wanted to know that what is the maximum value of a[i]%a[j] in an array 'a' consisting of n elements, where 1<=i,j<=n.We have to input the value of n i.e. the no. of elements in the array and the value of each element of the array..
You did want to know, but don't any more?


Why are the indices form 1 to N (inclusive)? The C++ prefers to use range 0 to N-1. Not that it matters. You can say 'k' to user and nevertheless use a[k-1].


The size of the array is determined during runtime. Hence, there is need for dynamic memory allocation. The C++ way:
1
2
3
4
5
6
7
size_t N = 0;
if ( std::cin >> N ) {
  std::vector<unsigned int> a( N );
  // read values
  // determine largest modulo
  // show result
}
Well please come to the question .I know that indexing is from 0.please tell me some method for the above problem.
> Well please come to the question.

Would the sequence 'a' contain non-positive values?
please tell me some method for the above problem

Brute force:
Compute all possible modulo's. Find largest of them. You do know how to find the largest value from a set of numbers, don't you?
Topic archived. No new replies allowed.