Необходимо вывести строку prime, если число простое, или composite, если число составное.
Answers & Comments
kitchenrecords
Function IsPrime(x: integer): boolean; var s, n: integer; begin Result := x > 1; s := Trunc(Sqrt(x)) + 1; n := 1; while (n < s) and Result do begin n := n + 1; Result := Result and (x mod n > 0); end; end;
var x, s: integer; begin readln(x); if IsPrime(x) then writeln('prime') else writeln('composite'); end.
Answers & Comments
var s, n: integer;
begin
Result := x > 1;
s := Trunc(Sqrt(x)) + 1;
n := 1;
while (n < s) and Result do begin
n := n + 1;
Result := Result and (x mod n > 0);
end;
end;
var x, s: integer;
begin
readln(x);
if IsPrime(x) then
writeln('prime')
else
writeln('composite');
end.