-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsample005.ptuc
51 lines (40 loc) · 1.01 KB
/
sample005.ptuc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
program calculate;
var limit, number, counter: integer;
function prime(n: integer): boolean;
var i: integer; isPrime: boolean;
begin
if n < 0 then
result := prime(-n)
else if n < 2 then
result := false
else if n = 2 then
result := true
else if n mod 2 = 0 then
result := false
else begin
i := 3;
isPrime := true;
while isPrime and i > 0 and (i < n div 2) do begin
isPrime := n mod i <> 0;
i := i+2
end;
result := isPrime
end;
return
end;
begin
limit := readInteger();
counter := 0;
number := 2;
while number <= limit do begin
if prime(number) then begin
counter := counter + 1;
writeInteger(number);
writeString(" ")
end;
number := number + 1
end;
writeString("\n");
writeInteger(counter);
writeString("\n")
end.