Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- EMIRP.PAS, computes numbers that are prime numbers when read backwards
- to forwards, too, e.g., 13 17 31 37 71 73 79 97. To compile run "fpc emirp.pas".
- Copyright (C) <February 01, 2016> Henning Polzer,
- send comments and error reports to: h underscore polzer at gmx dot de.
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- }
- PROGRAM mirpzahlen_berechnen;
- TYPE Tgz = int64; { Standard: integer }
- VAR i, og, ug: Tgz;
- PROCEDURE emirp (zahl: Tgz);
- VAR h: Tgz;
- FUNCTION prim (zahl: Tgz): boolean; { Primzahl? }
- VAR k: Tgz;
- BEGIN { prim }
- prim := true;
- k := 3;
- IF zahl / 2 = trunc (zahl / 2) THEN prim := false;
- IF zahl / 2 <> trunc (zahl / 2) THEN
- WHILE ((zahl / k <> trunc (zahl / k)) AND (k * k < zahl)) DO
- k := k + 2;
- IF zahl / k = trunc (zahl / k) THEN prim := false;
- CASE zahl OF
- 1 : prim := false;
- 2, 3, 5: prim := true
- END { case }
- END; { prim }
- FUNCTION spiegelzahl (zahl: Tgz): Tgz;
- VAR div_erg, s, z: Tgz;
- BEGIN { spiegelzahl }
- s := 0;
- z := zahl;
- IF z < 10 THEN s := z ELSE
- REPEAT
- div_erg := trunc (z / 10);
- s := (s + (z - div_erg * 10)) * 10;
- IF div_erg < 10 THEN s := s + div_erg;
- z := div_erg
- UNTIL z < 10;
- spiegelzahl := s
- END; { spiegelzahl }
- BEGIN { emirp }
- h := spiegelzahl (zahl);
- IF h <> zahl THEN { (Primzahl)palindrom ausser acht lassen }
- IF (prim (zahl) AND prim (h)) THEN write (zahl, ' ')
- END; { emirp }
- BEGIN { Hauptprogramm }
- write ('Untergrenze: '); readln (ug);
- write ('Obergrenze : '); readln (og);
- i := ug;
- IF i < 13 THEN i := 13;
- REPEAT
- emirp (i);
- i := i + 1
- UNTIL i > og;
- writeln
- END.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement