Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MODULE erastoten;
- FROM InOut IMPORT WriteString, WriteLn, WriteCard;
- FROM FIO IMPORT File, Open, Close, RdCard, EOF;
- CONST
- n = 1000;
- n2 = 1000;
- TYPE
- CL = SET OF [2..n];
- INTR = [0..n2];
- VAR
- primes : CL;
- arr : ARRAY INTR OF CARDINAL;
- f : File;
- i : CARDINAL;
- PROCEDURE ES(): CL;
- //functional PROCEDURE for erastoten sieve
- VAR
- i, next : CARDINAL;
- sieve, prime : CL;
- BEGIN
- sieve := CL{2..n};
- prime := CL{};
- next := 2;
- REPEAT
- WHILE NOT (next IN sieve) DO
- INC(next)
- END;
- INCL(prime, next);
- i := next;
- WHILE i <= n DO
- EXCL(sieve,i);
- i := i + next
- END
- UNTIL sieve = CL{};
- RETURN prime;
- END ES;
- BEGIN
- //Enter name of file!
- f:= Open('name.txt');
- i := 0;
- EOF := FALSE;
- WHILE NOT EOF DO
- INC(i);
- arr[i] := RdCard(f);
- END;
- Close(f);
- primes := ES();
- FOR i := 1 TO n2 DO
- IF arr[i] IN primes THEN
- WriteString('Number ');
- WriteCard(arr[i],0);
- WriteString(' from input list is a prime number!')
- WriteLn
- END
- END;
- END erastoten.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement