Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Var
- i : LongInt;
- R : array [0..3] of LongInt;
- x : LongInt;
- n : LongInt;
- Coef : Array [1..4] of LongInt;
- Function F (x : LongInt) : Boolean;
- var
- q,
- y : LongInt;
- begin
- if (Coef [4] mod x <> 0)
- then
- begin
- F := False;
- Exit;
- end;
- q := Coef [3] + Coef [4] div x;
- if (q mod x <> 0)
- then
- begin
- F := False;
- Exit;
- end;
- y := Coef [2] + q div x;
- if (Coef [1] = 0)
- then
- if (y = 0)
- then
- begin
- F := True;
- Exit;
- end
- else
- begin
- F := False;
- Exit;
- end;
- if (y mod Coef [1] = 0)
- and
- (- y div Coef [1] = x)
- then
- F := True
- else
- F := False;
- end;
- Function Rep (x : Integer) : Boolean;
- var
- i : byte;
- begin
- for i := 1 to 3 do
- if (R [i] = x)
- then
- begin
- Rep := True;
- Exit;
- end;
- Rep := False;
- end;
- Begin
- Read (Coef [1], Coef [2], Coef [3], Coef [4]);
- n := 0;
- for i := 4 downto 1 do
- if (Coef [i] <> 0)
- then
- begin
- n := Coef [i];
- Break;
- end;
- if (n = 0)
- then
- begin
- Write (-1);
- Exit;
- end;
- for i := 0 to 3 do
- R [i] := 0;
- if (Coef [4] = 0)
- then
- Inc (R [0]);
- n := Abs (n);
- for x := 1 to Trunc (Sqrt (n)) do
- if (n mod x = 0)
- then
- begin
- if (F (x))
- and
- not (Rep (x))
- then
- begin
- Inc (R [0]);
- R [R [0]] := x;
- end;
- if (F (-x))
- and
- not (Rep (-x))
- then
- begin
- Inc (R [0]);
- R [R [0]] := -x;
- end;
- if (F (n div x))
- and
- not (Rep (n div x))
- then
- begin
- Inc (R [0]);
- R [R [0]] := n div x;
- end;
- if (F (- n div x))
- and
- not (Rep (- n div x))
- then
- begin
- Inc (R [0]);
- R [R [0]] := - n div x;
- end;
- end;
- for i := 1 to (R [0] - 1) do
- for n := 1 to (R [0] - i) do
- if (R [n] > R [n + 1])
- then
- begin
- x := R [n];
- R [n] := R [n + 1];
- R [n + 1] := x;
- end;
- Write (R [0]);
- for i := 1 to R [0] do
- Write (' ', R [i]);
- End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement