记录编号 172726 评测结果 AAAAAAAAA
题目名称 [USACO 1.5] 回文质数 最终得分 100
用户昵称 GravatarFoolMike 是否通过 通过
代码语言 Pascal 运行时间 0.395 s
提交时间 2015-07-26 15:32:35 内存使用 0.15 MiB
显示代码纯文本
var
a,b,c,d,w,i,j:longint;
f:array[1..9]of integer;
begin
assign(input,'pprime.in');
reset(input);
assign(output,'pprime.out');
rewrite(output);
readln(a,b);
if a mod 2=0 then a:=a+1;
if b>9989899 then b:=9989899;

c:=a;
while a<>0 do
  begin
  inc(w);
  f[w]:=a mod 10;
  a:=a div 10;
  end;

repeat
  i:=1;
  for j:=1 to w div 2 do
  if f[j]<>f[w+1-j] then i:=0;
  if i=0 then
    begin
    f[1]:=f[1]+2;
    c:=c+2;
    if c>b then exit;
    j:=1;
    while f[j]>=10 do
      begin
      inc(f[j+1],f[j] div 10);
      f[j]:=f[j] mod 10;
      inc(j);
      end;
    if j>w then w:=j;
    end;
  {for j:=w downto 1 do
  write(f[j]);
  writeln;}
  until i=1;

{writeln(c);}

while c<=b do
  begin
  i:=1;
  for j:=2 to round(sqrt(c)) do
  if c mod j=0 then i:=0;
  if i=1 then
    begin
    for j:=w downto 1 do
    write(f[j]);
    writeln;
    end;

  i:=0;
  repeat
    if i=0 then
      begin
      f[1]:=f[1]+2;
      c:=c+2;
      if c>b then exit;
      j:=1;
      while f[j]>=10 do
        begin
        inc(f[j+1],f[j] div 10);
        f[j]:=f[j] mod 10;
        inc(j);
        end;
      if j>w then w:=j;
      end;
    i:=1;
    for j:=1 to w div 2 do
    if f[j]<>f[w+1-j] then i:=0;
    until i=1;
  end;

close(input);
close(output);
end.