pascal 绝对素数

[复制链接]
查看11 | 回复3 | 2011-2-1 09:31:33 | 显示全部楼层 |阅读模式
4.如果一个自然数是素数,且它的数字位置经过对换后仍为素数,则称为绝对素数,例如13。试求出所有二位绝对素数。
我试了试~~但是为什么会错呢?
我的程序如下
program ex414;
var a,b:integer;
function d(m:integer):integer;
var g,z:integer;
begin
z:=m div 10;
g:=m mod 10;
d:=g*10+z;
end;
functions(p:integer):integer;
var i:integer; o:boolean;
begin
o:=false;
for i:=2 to p-1 do
if p mod i =0 then o:=true;
if o then s:=10000 else s:=p;
end;
begin
for a:=10 to 99 do
begin
if s(a) =a then b:=d(a);
if b=1 or 2 then write(a,' ':3) else if s(b)=b thenwrite(a,' ':3);
end;
readln;
end.
求助!~~

回复

使用道具 举报

千问 | 2011-2-1 09:31:33 | 显示全部楼层
倒数第3、4行找到了吗if s(a) =a then b:=d(a);if b=1 or 2 then write(a,' ':3) else if s(b)=b thenwrite(a,' ':3);我猜测1L是考虑了你很多地方没有优化到数字大了运行时间会吃不消但是关系结果的只有这句话我认为(以上机验证。)应该if s(a) =a then begin b:=d(a); if b=1 or 2 then write(a,' ':3) else if s(b)=b thenwrite(a,' ':3);end;为什么捏~下面给您分析:你本来的第一句语句只有当s(a)=a时b才可被赋值但是如果s(a
回复

使用道具 举报

千问 | 2011-2-1 09:31:33 | 显示全部楼层
program ex414;function ExchPos(m:integer):integer;begin
ExchPos:=(m mod 10)*10+(m div 10);end;function isPrime(p:integer):Boolean;var i:integer;begin
回复

使用道具 举报

千问 | 2011-2-1 09:31:33 | 显示全部楼层
你犯的错误也太多了。需要好好练练program ex414;function ExchPos(m:integer):integer;begin
ExchPos:=(m mod 10)*10+(m div 10);end;function isPrime(p:integer):Boolean;var i
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行