1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| program premier;
uses crt;
var n,m,i:integer;
function testp(n:integer):boolean;
var i:integer;
begin
if n=1 then testp:=false else
begin
i:=2;
while (i<=n) and (n mod i <> 0) do i:=i+1;
if i=n then testp:=true else testp:=false
end;
end;
function testh(n:integer):boolean;
var ch:string; k,i,s,e:integer;
begin
str(n,ch);
s:=0;
for i:=1 to length(ch) do
begin
val(ch[i],k,e);
s:=s+k
end;
if s=n then testh:=true else testh:=false
end;
begin
for n:=100 to 150 do
begin
if ( testp(n-1)=true and testh(n)=true )
then write(n:4);
end;
end. |
Partager