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, divisori: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 divisori[i]:=divis1[i];
  33. for i:=contadivisori+1 to contadivisori*2 do divisori[i]:=divis2[2*contadivisori-i+1];
  34. for i:=1 to contadivisori*2 do write(divisori[i],' '); writeln;
  35. for i:=1 to contadivisori*2 do
  36. begin
  37. if (A mod divisori[i]) =0 then increment1:=0
  38. else increment1:=divisori[i] - (A mod divisori[i]);
  39. if (B mod divisori[i]) =0 then increment2:=0
  40. else increment2:=divisori[i] - (B mod divisori[i]);
  41. if (increment1+increment2)>K then continue
  42. else if (increment1+increment2)<K then begin if ((K-(increment1+increment2)) mod (divisori[i])) =0 then if divisori[i]>G then G:=divisori[i]
  43. else continue; end
  44. else if (increment1+increment2)=K then begin if divisori[i]>G then G:=divisori[i]
  45. else continue; end;
  46. end;
  47. writeln(G);
  48. end;
  49. end.
  50.  
Success #stdin #stdout 0.01s 5268KB
stdin
4
7 11 3
18 9 3
58 38 14
68 94 231
stdout
21 7 3 1 
7
30 15 10 6 5 3 2 1 
10
110 55 22 11 10 5 2 1 
22
393 131 3 1 
131