SERGE_BLIZNUK
Silver Member | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору Код: Program TstPrime; function isPrime(X: LongInt): boolean; var i: integer; Begin isPrime:=false; if x<2 then Exit; if not odd(x) and (x<>2) { проверяем на чётность } then exit; i:=3; while i <= sqrt(x) do { проверяем только нечётные } begin if x mod i = 0 then Exit; inc(i,2); end; isPrime:=true; End; var n : Longint; begin WriteLn('Введите число n: '); Readln(n): if isPrime(n) then WriteLn('prime') else WriteLn('composite'); readln; end. | |