最大公约数: { Author:wzx961008 Problem:UVa 11417-GCD Verdict:Accepted Language:PASCAL Run Time:0.044s Submission Date:2011-02-11 03:54:23 } var i,j,g,n:longint; f:array[1..501,1..501]of longint; function gcd(a,b:longint):longint; begin if a=0 then exit(b) else exit(gcd(b mod a,a)) end; begin while true do begin readln(n); if n=0 then break; g:=0; for i:=1 to n-1 do for j:=i+1 to n do begin if f[i,j]=0 then begin f[i,j]:=gcd(i,j); f[j,i]:=f[i,j]; end; g:=g+f[i,j]; end; writeln(g); end; end.