Post
by kiha » Mon Mar 08, 2004 11:02 pm
Hi,
I tested my program on all your tests,
I read all topics about 10235 -- Simply Emirp,
but I still get WA.
I apologise for putting my code here, but I can't work out what's wrong -- it seems to be all right :/
A little explanation :
s, os -- numbers read as strings : s -- read normally, os -- read backwards
g, og -- real numbers that I am to check
n, nn -- bools declaring : n -- whether original number is a prime, nn -- whether the same number read backwards is a prime
[pascal]
program miazio;
function odwr (s:string):string;
var
pk:byte;
qpa:string;
begin
pk:=length (s) + 1;
qpa:='';
repeat
dec (pk);
qpa:=qpa + s[pk]
until pk <= 1;
odwr:=qpa;
end;
var
s, os:string;
i, j, l, k, lp, p, g, og:longint;
n, nn:boolean;
kurde:set of char;
begin
kurde:=['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
while not eof do
begin
readln (s);
os:=odwr (s);
g:=0; og:=0;
for lp:=1 to length (s) do
g:=g * 10 + ord (s[lp]) - 48;
for lp:=1 to length (os) do
og:=og * 10 + ord (os[lp]) - 48;
lp:=0;
k:=1;
nn:=false;
repeat
inc (k);
if og mod k = 0 then
inc (lp);
until (k = trunc (sqrt (og))+1) or (lp > 0);
if (lp = 0) then
nn:=true;
lp:=0;
k:=1;
n:=false;
repeat
inc (k);
if g mod k = 0 then
inc (lp);
until (k = trunc (sqrt (g))+1) or (lp > 0);
if lp = 0 then
n:=true;
if g = 1 then n:=true;
if og = 1 then nn:=false;
if (g = 2) then n:=true;
if og = 2 then nn:=true;
if (og = g) and (n) then nn:=false;
if (not n) and (not nn) then writeln (g, ' is not prime.');
if n and (not nn) then writeln (g, ' is prime.');
if nn then writeln (g, ' is emirp.');
n:=false;
nn:=false;
end;
end.
[/pascal]
kiha