fork download
  1. Program divisor;
  2.  
  3. var
  4. A, B, G, K, T, i,test,radq, somma, contadivisori, increment1, increment2 : LongInt;
  5. divis1, divis2:array[1..100000] of longint;
  6.  
  7. procedure trovadivisori (x:longint);
  8. var y,h:longint;
  9.  
  10. begin
  11. y:=2; h:=2;
  12. repeat
  13. if (x mod y =0) then begin divis1[h]:= x div y; divis2[h]:=y; h:=h+1; end;
  14. y:=y+1;
  15. until y>trunc(sqrt(x));
  16. contadivisori:=h-1;
  17. end;
  18.  
  19. begin
  20. { assign(input, 'input.txt'); reset(input);
  21.   assign(output, 'output.txt'); rewrite(output);
  22. }
  23.  
  24. ReadLn(T);
  25. for test:=1 to T do begin
  26. ReadLn(A, B, K);
  27. somma:=A+B+K;
  28. radq:=trunc(sqrt(somma));
  29. divis2[1]:=1; divis1[1]:=somma;
  30. trovadivisori(somma);
  31. G := 0;
  32. for i:=1 to contadivisori do
  33. begin
  34. if A mod divis1[i]=0 then increment1:= 0 else increment1:=divis1[i] - (A mod divis1[i]);
  35. if B mod divis1[i]=0 then increment2:= 0 else increment2:=divis1[i] - (B mod divis1[i]);
  36. if (increment1+increment2)>K then continue
  37. else
  38. if (increment1+increment2)<=K then if divis1[i]>G then G:=divis1[i];
  39. end;
  40. writeln(G);
  41. end;
  42. end.
  43.  
Success #stdin #stdout 0s 5288KB
stdin
4
7 11 3
18 9 3
58 38 14
68 94 231
stdout
7
10
22
131