社区讨论

回文质数 第七、九两个测试点超时

P1217[USACO1.5] 回文质数 Prime Palindromes参与者 3已保存回复 4

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
4 条
当前快照
1 份
快照标识符
@mi5hlo6z
此快照首次捕获于
2025/11/19 12:13
4 个月前
此快照最后确认于
2025/11/19 12:13
4 个月前
查看原帖
程序如下
CPP
program zlw;
var 
        a:array[5..100000000] of 0..1;
        m,n,i,j,l,k,code:longint;
        s:string;
function check(o:longint):boolean;
var i,j:longint;
begin
j:=0;
for i:=2 to trunc(sqrt(o)) do
if o mod i=0 then begin j:=1; break; end;
if j=1 then exit(false) else exit(true);
end;
begin
readln(m,n);
for i:=m to n do a[i]:=1;
if m<7 then writeln(5);
if m<10 then begin writeln(7); m:=11; end;
i:=m;
for i:=m to n do
begin
str(i,s);
l:=length(s);
for j:=1 to l div 2 do
if (s[j]<>s[l-j+1])  then begin a[i]:=0; break; end;
end;
i:=m;
while(i<=n) do
begin
if (a[i]=1) then
 begin
 if check(i) then writeln(i);
 end;
if (i=m) and (not (odd(m))) then inc(i) else inc(i,2);
end;
end.

回复

4 条回复,欢迎继续交流。

正在加载回复...