Advertisement
mrlolthe1st

Untitled

Oct 7th, 2021
1,311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.70 KB | None | 0 0
  1. Var
  2.   i : LongInt;
  3.  
  4.   R : array [0..3] of LongInt;
  5.    
  6.   x : LongInt;
  7.  
  8.   n : LongInt;
  9.  
  10.   Coef : Array [1..4] of LongInt;
  11.  
  12. Function F (x : LongInt) : Boolean;
  13.  
  14. var
  15.   q,
  16.   y : LongInt;
  17.  
  18. begin
  19.    
  20.   if (Coef [4] mod x <> 0)
  21.     then
  22.       begin
  23.         F := False;
  24.  
  25.         Exit;
  26.       end;
  27.  
  28.   q := Coef [3] + Coef [4] div x;
  29.  
  30.   if (q mod x <> 0)
  31.     then
  32.       begin
  33.         F := False;
  34.  
  35.         Exit;
  36.       end;
  37.  
  38.   y := Coef [2] + q div x;
  39.  
  40.   if (Coef [1] = 0)
  41.     then
  42.      if (y = 0)
  43.        then
  44.          begin
  45.            F := True;
  46.  
  47.            Exit;
  48.          end
  49.        else
  50.          begin
  51.            F := False;
  52.  
  53.            Exit;
  54.          end;
  55.  
  56.   if (y mod Coef [1] = 0)
  57.      and
  58.      (- y div Coef [1] = x)
  59.     then
  60.       F := True
  61.     else
  62.       F := False;
  63. end;
  64.  
  65.  
  66. Function Rep (x : Integer) : Boolean;
  67.  
  68. var
  69.   i : byte;
  70.  
  71. begin
  72.   for i := 1 to 3 do
  73.     if (R [i] = x)
  74.       then
  75.         begin
  76.           Rep := True;
  77.  
  78.           Exit;
  79.         end;
  80.  
  81.   Rep := False;
  82. end;
  83.  
  84.  
  85. Begin
  86.   Read (Coef [1], Coef [2], Coef [3], Coef [4]);
  87.  
  88.  
  89.   n := 0;
  90.   for i := 4 downto 1 do
  91.     if (Coef [i] <> 0)
  92.       then
  93.         begin
  94.           n := Coef [i];
  95.  
  96.           Break;
  97.         end;
  98.  
  99.   if (n = 0)
  100.     then
  101.       begin
  102.         Write (-1);
  103.  
  104.         Exit;
  105.       end;
  106.  
  107.   for i := 0 to 3 do
  108.     R [i] := 0;
  109.  
  110.  
  111.   if (Coef [4] = 0)
  112.     then
  113.        
  114.      
  115.       Inc (R [0]);
  116.  
  117.  
  118.   n := Abs (n);
  119.   for x := 1 to Trunc (Sqrt (n)) do
  120.     if (n mod x = 0)
  121.       then
  122.         begin
  123.           if (F (x))
  124.              and
  125.              not (Rep (x))
  126.             then
  127.               begin
  128.                 Inc (R [0]);
  129.                 R [R [0]] := x;
  130.               end;
  131.  
  132.           if (F (-x))
  133.              and
  134.              not (Rep (-x))
  135.             then
  136.               begin
  137.                 Inc (R [0]);
  138.                 R [R [0]] := -x;
  139.               end;
  140.  
  141.           if (F (n div x))
  142.              and
  143.              not (Rep (n div x))
  144.             then
  145.               begin
  146.                 Inc (R [0]);
  147.                 R [R [0]] := n div x;
  148.               end;
  149.  
  150.           if (F (- n div x))
  151.              and
  152.              not (Rep (- n div x))
  153.             then
  154.               begin
  155.                 Inc (R [0]);
  156.                 R [R [0]] := - n div x;
  157.               end;
  158.         end;
  159.  
  160.   for i := 1 to (R [0] - 1) do
  161.     for n := 1 to (R [0] - i) do
  162.       if (R [n] > R [n + 1])
  163.         then
  164.           begin
  165.             x := R [n];
  166.             R [n] := R [n + 1];
  167.             R [n + 1] := x;
  168.           end;
  169.  
  170.  
  171.   Write (R [0]);
  172.  
  173.   for i := 1 to R [0] do
  174.     Write (' ', R [i]);
  175.  
  176.  
  177.  
  178. End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement