# Поиск простых чисел (без оптимизации)

Mar 24th, 2021
883
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. program p25;
2.
3. uses crt;
4.
5. function isThreeNonTrivialDivision( x : integer ):boolean;
6. var count_div : integer;
7.      division : integer;
8. begin
9.     count_div := 0;
10.
11.     if( trunc(sqrt(x)) = sqrt(x) ) then
12.        begin
13.           count_div := 1;
14.           for division := 2 to trunc(sqrt(x)) - 1 do
15.               if ( x mod division = 0 ) then count_div := count_div + 2;
16.           if count_div = 3 then
17.              result := true
18.           else
19.              result := false;
20.        end
21.     else
22.        result := false;
23. end;
24.
25. function getMaxDiv(x : integer) : integer;
26. var division, max_div : integer;
27. begin
28.     for division := 2 to x - 1 do
29.         if ( x mod division = 0 ) then
30.           begin
31.             max_div := x div division;
32.             break;
33.           end;
34.     result := max_div;
35. end;
36.
37. procedure solution(x_start, x_end : integer);
38. var x : integer;
39. begin
40.     for x := x_start to x_end do begin
41.         if isThreeNonTrivialDivision(x) then
42.            writeln('x = ', x,' : макс. делитель = ', getMaxDiv(x));
43.     end;
44. end;
45.
46. var a : integer;
47.     b : integer;
48.
49. begin
50.    a := 3;
51.    b := 30;
52.
53.    solution(a, b);
54. end.
RAW Paste Data