Does anybody know how to make a program in Pascal with this task?

Task :: MaxGCD
For given n integers, you have to find the pair that has the greatest GCD (greatest common divider).


INPUT:
the first line of the standard input will contain the number n, and the next n lines will contain the number, each being at most 1 000 000 000. n 1 000.


OUTPUT:
To the standard output, write the GCD of the pair that has the biggest GCD.



Input:

6
9
6
391
8
24
60

Output:

12





Input:

2
71
16899

Output:

1

?2009-02-11T07:09:49Z

Favorite Answer

Try to modify this program which uses only 2 integers, you must use arrays.

program GCDProgram (input, output);

var

x, y: integer;

function Gcd (m, n : integer) : integer;

var

r: integer; {remainder}

begin

while n <> 0 do

begin

r := m mod n;

m := n;

n := r

end;

Gcd := m {returned result}

end;

begin{GcdProgram}

writeln('PROGRAM GcdProgram');

while true do {infinite loop - exit by an interrupt}

begin

write('Enter two integers: ');

readln(x,y);

writeln('GCD(', x:4, ',', y:4, ') = ', (Gcd(x, y)):4)

end

end. GcdProgram