{program jacobi; Shell for the function Jacobi} {$N+,E+} uses CRT, nothy; {$I GetInput.i } var P, Q, t : comp; x : extended; code, i, J, {The Jacobi symbol} x0, y0 : integer; InputOk : Boolean; begin InputOk := False; if (ParamCount = 2) then begin InputOk := True; Val(ParamStr(1), x, code); if (frac(x) = 0) and (code = 0) and (x > -MaxAllow) and (x < MaxAllow) then P := x else InputOk := False; Val(ParamStr(2), x, code); t := x/2; if (frac(x) = 0) and (code = 0) and (x > 0) and (x < MaxAllow) and (2*t <> x) then Q := x else InputOk := False; end; if not InputOk then begin WriteLn('Will compute the Jacobi symbol (P/Q).'); P := GetInput(WhereX, WhereY, ' Enter P = ', ' (|P| ó 999999999999999999)', -MaxAllow+1, MaxAllow-1); x0 := WhereX; y0 := WhereY; repeat Q := GetInput(x0, y0, 'Enter odd Q = ', ' (1 ó Q ó 999999999999999999)', 1, MaxAllow-1); t := Q/2 until Q <> 2*t; for i := 1 to 3 do begin GoToXY(1, WhereY - 1); ClrEoL end end; J := Jacobi(P, Q); WriteLn('(', P:1:0, '/', Q:1:0, ') = ', J:1) end.