fork(2) download
  1. var S, K, A, B, N, rez:longint;
  2. begin
  3. readln (S, K, A, B);
  4. if s*a=b then writeln (s*k)
  5. else
  6. begin
  7. n:=1;
  8. while n<1001 do
  9. begin
  10. if (abs(s*a-b)) mod n =0 then
  11. begin
  12. rez:=((b-s*a) div n) +s*k;
  13. if (rez>=0) and (a>n*k) then
  14. begin
  15. writeln (rez);
  16. halt;
  17. end;
  18. end;
  19. inc (n);
  20. end;
  21. if n=1001 then writeln (-1);
  22. end;
  23. end.
Success #stdin #stdout 0s 232KB
stdin
Standard input is empty
stdout
0