切换到宽版
  • 16328阅读
  • 4回复

usaco中求给定区间内的回文质数~~急求 [复制链接]

上一主题 下一主题
离线linjianman
 
只看楼主 倒序阅读 0 发表于: 2007-09-05
看下有什么错。。为什么输不出来。。 单步调试的时候又能输得出。。
program pprime1;
var a,b,k:longint; sum:boolean;
sushu:array[1..10000000] of 0..1 ;
procedure pprime(x,y:longint);
var i,j:longint;
begin
for i:=x to y do
for j:=2 to trunc(sqrt(i)) do
if  (i mod j=0) then sushu:=0;
end;
function huiwen(x:longint):boolean;
var i1,j1:longint; s,s1,s2:string;
begin
str(x,s);
i1:=length(s);
s1:=copy(s,1,i1 div 2);
s2:=copy(s,(i1 div 2 +1),i1);
for j1:=11 to i1 div 2 do
if s1[j1]=s2[i1-j1] then  huiwen:=true else huiwen:=false;
end;
begin
read(a,b);
for k:=a to b do
sushu[k]:=1;
pprime(a,b);
for k:=a to b do
if sushu[k]=1 then
begin
sum:=huiwen(k);
if sum=true then
writeln(k);
end;
end.
离线linjianman
只看该作者 1 发表于: 2007-09-10
看下有什么错。。为什么输不出来。。 单步调试的时候又能输得出。。
program pprime1;
var a,b,k:longint; sum:boolean;
sushu:array[1..10000000] of 0..1 ;
procedure pprime(x,y:longint);
var i,j:longint;
begin
for i:=x to y do
for j:=2 to trunc(sqrt(i)) do
if  (i mod j=0) then sushu:=0;
end;
function huiwen(x:longint):boolean;
var i1,j1:longint; s,s1,s2:string;
begin
str(x,s);
i1:=length(s);
s1:=copy(s,1,i1 div 2);
s2:=copy(s,(i1 div 2 +1),i1);
for j1:=1 to i1 div 2 do
if s1[j1]=s2[i1-j1] then  huiwen:=true else huiwen:=false;
end;
begin
read(a,b);
for k:=a to b do
sushu[k]:=1;
pprime(a,b);
for k:=a to b do
if sushu[k]=1 then
begin
sum:=huiwen(k);
if sum=true then
writeln(k);
end;
end.
离线zxfx100
只看该作者 2 发表于: 2007-09-24
楼上的你不累吗?
离线superacid
只看该作者 3 发表于: 2007-11-12
由这么灌水的吗?!
离线yonghu86cs
只看该作者 4 发表于: 2008-02-23
yun
快速回复
限100 字节
 
上一个 下一个